python3常用的三大函数之一map

lambda函数

1,add = lambda x, y : x+y

2,print(add(1,2))



1·map函数

2·# map(func,seq[]) return  list  对seq 中的item依次执政func(item),返回一个可迭代对象,需要用list/tuple将其接收

3·str = ('a', 'b','c', 'd')

4·def fun2(s): return s + ".txt"

5,ret = list(map(fun2, str))

6,print(ret)

学习python加python编程语言学习扣群 5152+67276

# 实现首字母的大写其余字母小写

a = ['adarm','LSssfk','akjfsT']

def function(x):

    return x[0].upper() + x[1:].lower()

print(map(function,a))

print(list(map(function,a)))




猜你喜欢

转载自blog.51cto.com/14078334/2331668