class Person(object):
def __init__(self,name,gender,brith,job):
self.name=name
self.gender=gender
self.brith=brith
self.job=job
xiaoming = Person('Xiao Ming', 'Male', '1990-1-1', job='Student')
print xiaoming.name
print xiaoming.job
def __init__(self,name,gender,brith,job):
self.name=name
self.gender=gender
self.brith=brith
self.job=job
xiaoming = Person('Xiao Ming', 'Male', '1990-1-1', job='Student')
print xiaoming.name
print xiaoming.job
2016-09-27
a,b = a,a + b
等价于
a = a , b= a ,b = a + b // a, b = a , b = a + a
等价于
a = a , b= a ,b = a + b // a, b = a , b = a + a
2016-09-27
这是Python的多态吗,我只知道在Java中这叫方法的继承和重写。Python非得把原有语言体系中的定义都推翻重新定义一遍吗?我看不出任何的优雅可言。
2016-09-27
i = 0
def count():
global i
i = i + 1
return i * i
print count(), count(), count()
def count():
global i
i = i + 1
return i * i
print count(), count(), count()
2016-09-27
可以把__init__改成这样
def __init__(self, p, q):
m,n=p,q
while n!=0:
m,n=n,m%n
self.p = p/m
self.q = q/m
def __init__(self, p, q):
m,n=p,q
while n!=0:
m,n=n,m%n
self.p = p/m
self.q = q/m
2016-09-26
想用递归的方法写半天没写出来,idle里老是报错,看到答案都惊了,精湛的技巧源于对规则的熟练掌握,这些题真的很不错
2016-09-26
虽然现在学的很多答案对于新手来说完全有点蒙蔽,但是学习就是一个从不会到会的过程,只要你一直坚持下去,不断积累新的知识,那么那些在别人看来理所应当的知识 你也能够熟练的掌握
2016-09-26
if s1.upper()<s2.upper():
return -1
if s1.upper()>s2.upper():
return 1
return 0
return -1
if s1.upper()>s2.upper():
return 1
return 0
2016-09-26