class Fib(object):
def __init__(self, num):
i=0
n=0
self.list=[]
while(i<num):
if i==1:
n=1
self.list.append(n)
if len(self.list)>1:
n=n+self.list[-2]
i=i+1
def __init__(self, num):
i=0
n=0
self.list=[]
while(i<num):
if i==1:
n=1
self.list.append(n)
if len(self.list)>1:
n=n+self.list[-2]
i=i+1
2018-01-03
def cmp_ignore_case(s1, s2):
if s1[0].lower() > s2[0].lower():
return 1
if s1[0].lower() < s2[0].lower():
return -1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
if s1[0].lower() > s2[0].lower():
return 1
if s1[0].lower() < s2[0].lower():
return -1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2018-01-03
可以使用类名调用类属性和类方法,但不能用类名调用实例属性和实例方法;
可以是用实例化对象调用实例属性和实例方法,也可以调用类属性和类方法
可以是用实例化对象调用实例属性和实例方法,也可以调用类属性和类方法
2018-01-03
@property
def grade(self):
if self.__score >= 80:
return 'A'
elif self.__score < 60:
return 'C'
else:
return 'B'
def grade(self):
if self.__score >= 80:
return 'A'
elif self.__score < 60:
return 'C'
else:
return 'B'
2018-01-03
a,b,L = 0,1,[]
for x in range(num):
L.append(a)
a,b = b,a + b
self.numbers = L
for x in range(num):
L.append(a)
a,b = b,a + b
self.numbers = L
2018-01-03
if self.score == s.score:
return cmp(self.name, s.name)
return -cmp(self.score, s.score)
return cmp(self.name, s.name)
return -cmp(self.score, s.score)
2018-01-03
__score = 65
def __init__(self, name, score):
self.name = name
self.score = score
def get_grade(self):
if self.score == Person.__score :
return 'B-及格'
elif self.score > Person.__score :
return 'A-优秀'
def __init__(self, name, score):
self.name = name
self.score = score
def get_grade(self):
if self.score == Person.__score :
return 'B-及格'
elif self.score > Person.__score :
return 'A-优秀'
2018-01-03