发布时间:2019-09-24 08:38:58编辑:auto阅读(2215)
函数
>>> def ds(x):
return 2 * x + 1
>>> ds(5)
11
>>> lambda x : 2 * x + 1
<function <lambda> at 0x035C65D0>
>>> a = lambda x : 2 * x + 1 #lambda关键字来创建匿名函数
>>> a(5)
11
>>> def add(x,y):
return x + y
>>> add(3,4)
7
>>> b = lambda x,y : x + y
>>> b(3, 4)
7
>>> list(filter(None,[1,0,False,True])) #filter() 过滤器
[1, True]
>>> def odd(x):
return x % 2
>>> temp = range(10)
>>> show = filter(odd,temp)
>>> list(show)
[1, 3, 5, 7, 9]
>>> list(filter(lambda x : x % 2, range(10)))
[1, 3, 5, 7, 9]
>>> list(map(lambda x : x * 2, range(10))) #map() 会根据提供的函数对指定序列做映射
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
上一篇: python学习整理--3/3
下一篇: python3_00.入门
51714
51376
41807
38579
33060
30070
28738
23736
23646
22014
2232°
2918°
2439°
2386°
2959°
2387°
3194°
5250°
5067°
3618°