def prod(x, y):
return x*y
print reduce(prod, [2, 4, 5, 7, 12])
return x*y
print reduce(prod, [2, 4, 5, 7, 12])
2015-05-14
def format_name(s):
s=s.lower()
return s.capitalize()
print map(format_name, ['adam', 'LISA', 'barT'])
s=s.lower()
return s.capitalize()
print map(format_name, ['adam', 'LISA', 'barT'])
2015-05-14
def format_name(s):
s=s.lower()
return s.title()
print map(format_name, ['adam', 'LISA', 'barT'])
s=s.lower()
return s.title()
print map(format_name, ['adam', 'LISA', 'barT'])
2015-05-14
#初始化实例属性#(1)__init__可以在类创建实例时被自动调用,所以初始化属性操作可以写在__init__方法里。格式:def __init__(self,name,birth): self.name = name ; self.birth = birth;
(2)要定义关键字参数,使用**kw.除了使用self.name='XXX'来设置属性以外,还可以用setattr(self,name,'XXX')
(2)要定义关键字参数,使用**kw.除了使用self.name='XXX'来设置属性以外,还可以用setattr(self,name,'XXX')
2015-05-14
def prod(x, y):
return x*y
print reduce(prod, [2, 4, 5, 7, 12])
return x*y
print reduce(prod, [2, 4, 5, 7, 12])
2015-05-14
def cmp_ignore_case(s1, s2):
return cmp(s1.lower(), s2.lower())
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
return cmp(s1.lower(), s2.lower())
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2015-05-13
def calc_prod(lst):
def f(x,y):
return x*y
def lazy_prod():
return reduce(f,lst)
return lazy_prod
def f(x,y):
return x*y
def lazy_prod():
return reduce(f,lst)
return lazy_prod
2015-05-13