def __init__(self, num):
x=0
y=1
l=0
z=1
f=[0]
while z<10:
f.append(y)
l=y
y=y+x
x=l
z+=1
self.num=f
x=0
y=1
l=0
z=1
f=[0]
while z<10:
f.append(y)
l=y
y=y+x
x=l
z+=1
self.num=f
2018-04-08
def __cmp__(self, s):
if self.name!=s.name:
return -cmp(self.score,s.score)
return cmp(self.name,s.name)
if self.name!=s.name:
return -cmp(self.score,s.score)
return cmp(self.name,s.name)
2018-04-08
-------*******----------
class Student(Person):
__slots__ = ('score')
def __init__(self,name,gender,score):
super(Student,self).__init__(name,gender)
self.name = name
self.gender = gender
self.score = score
class Student(Person):
__slots__ = ('score')
def __init__(self,name,gender,score):
super(Student,self).__init__(name,gender)
self.name = name
self.gender = gender
self.score = score
2018-04-07
def __cmp__(self, s):
if self.score>s.score:
return -1
elif self.score<s.score:
return 1
else:
return 1 if self.name>s.name else -1
L = [Student('Tim', 99), Student('Bob', 88), Student('Alice', 99)]
print sorted(L)
if self.score>s.score:
return -1
elif self.score<s.score:
return 1
else:
return 1 if self.name>s.name else -1
L = [Student('Tim', 99), Student('Bob', 88), Student('Alice', 99)]
print sorted(L)
2018-04-07
装饰器是一种设计模式,那些说难的同学们,并不是Python难,而是你可能没有去真正理解装饰器这种设计模式的概念,建议先去弄明白装饰器的概念再来看用Python的实现,可能就很容易掌握了
2018-04-07