1.字符串首字母大寫,其餘小寫
L1 = ['adam', 'LISA', 'barT']
L2 = [s.capitalize() for s in L1]
print(L2)
2.數組內值相乘
def prod(L):
return reduce(lambda x,y:x*y, L)
print('3 * 5 * 7 * 9 =', prod([3, 5, 7, 9]))
3.返回函數計數器
def createCounter():
def counter():
a = 0
while True:
a= a+1
yield a
it = counter()
def number():
return next(it)
return number
4.匿名函數
L = list(filter(lambda x:x%2, range(1, 20)))
print(L)