初学python,从老师的python入门刷到这里,突然一脸懵逼,卡了一个礼拜也没懂明白装饰器咋回事...不得不去写了个小爬虫练手||| 装饰器放在这里讲是不是跳跃性太强了??
2018-01-08
class Person:
def __init__(self,name):
self.name = name
L = ['Bart','Adam','Lisa']
L1 = [Person(p) for p in L]
L2 = sorted(L1,key = lambda x:x.name)
for p in L2: print(p.name)
def __init__(self,name):
self.name = name
L = ['Bart','Adam','Lisa']
L1 = [Person(p) for p in L]
L2 = sorted(L1,key = lambda x:x.name)
for p in L2: print(p.name)
2018-01-08
def calc_prod(lst):
def calc(x,y): return x*y
def j():
return reduce(calc, lst)
return j
f = calc_prod([1, 2, 3, 4])
print f()
def calc(x,y): return x*y
def j():
return reduce(calc, lst)
return j
f = calc_prod([1, 2, 3, 4])
print f()
2018-01-08
说实话感觉这老师讲的太一笔带过了 就不能拿到视频中多讲解下吗??还没有看书来的清楚!!!
×××××××××××差评
×××××××××××差评
×××××××××××差评
×××××××××××差评
×××××××××××差评
×××××××××××差评
×××××××××××差评
×××××××××××差评
×××××××××××差评
×××××××××××差评
2018-01-07
return '(Student: %s,%s,%d)' %(self.name,self.gender,self.score)#这样也是可以运行通过的,有点没太懂__repr__与__str__ 的区别
2018-01-07
class Person(object):
def __init__(self, name, gender):
self.name = name
self.gender = gender
class Teacher(Person):
def __init__(self, name, gender, course):
super(Teacher,self).__init__(name,gender) #一定要记住要初始化父类
self.course = course
def __init__(self, name, gender):
self.name = name
self.gender = gender
class Teacher(Person):
def __init__(self, name, gender, course):
super(Teacher,self).__init__(name,gender) #一定要记住要初始化父类
self.course = course
2018-01-07
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-06
class Person(object):
__count = 0
@classmethod
def how_many(cls): #标准答案
return cls.__count
def __init__(self,name):
self.name = name
Person.__count = Person.__count + 1
print Person.how_many()
p1 = Person('Bob')
print Person.how_many()
__count = 0
@classmethod
def how_many(cls): #标准答案
return cls.__count
def __init__(self,name):
self.name = name
Person.__count = Person.__count + 1
print Person.how_many()
p1 = Person('Bob')
print Person.how_many()
2018-01-06