看不懂的可以去看书,不是你水平不行,可能老师说的是有点那啥。我用了三年python了,没觉得有那么复杂。可能是没说清楚具体操作原理,也有可能是函数的名字太长了吧,对新手是真的不友好
2017-10-20
import functools
def sorted_custom(x):
return x.upper()
sorted_ignore_case = functools.partial(sorted,key=sorted_custom)
print sorted_ignore_case(['bob', 'about', 'Zoo', 'Credit'])
def sorted_custom(x):
return x.upper()
sorted_ignore_case = functools.partial(sorted,key=sorted_custom)
print sorted_ignore_case(['bob', 'about', 'Zoo', 'Credit'])
2017-10-19
class Person(object):
__count = 0
@classmethod
def how_many(cls):
cls.count= Person.__count
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):
cls.count= Person.__count
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
2017-10-18
def calc_prod(lst):
def Cal():
sum = 1
for num in lst:
sum = sum *num
return sum
return Cal
f = calc_prod([1, 2, 3, 4])
print f()
def Cal():
sum = 1
for num in lst:
sum = sum *num
return sum
return Cal
f = calc_prod([1, 2, 3, 4])
print f()
2017-10-18
def cmp_ignore_case(s1, s2):
if s1[0].upper() < s2.upper():
return -1
elif s1[0].upper() == s2.upper():
return 0
else :
return 1
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
if s1[0].upper() < s2.upper():
return -1
elif s1[0].upper() == s2.upper():
return 0
else :
return 1
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2017-10-18
def calc_prod(lst):
def sec_prod():
def prod(x,y):
return x*y
return reduce(prod,lst)
return sec_prod
f = calc_prod([1, 2, 3, 4])
print f()
def sec_prod():
def prod(x,y):
return x*y
return reduce(prod,lst)
return sec_prod
f = calc_prod([1, 2, 3, 4])
print f()
2017-10-18
def calc_prod(lst):
def sec_prod():
def prod(x,y):
return x*y
print reduce(prod,lst)
return sec_prod
f = calc_prod([1, 2, 3, 4])
print f()
def sec_prod():
def prod(x,y):
return x*y
print reduce(prod,lst)
return sec_prod
f = calc_prod([1, 2, 3, 4])
print f()
2017-10-18