Python基础-常用的内置函数

时间:2024-12-28 12:33:21
内置函数filter
str = ['a', 'b', 'c', 'd']
def fansik(num):
if num != "a":
return num ret = filter(fansik, str)
print(ret)
print(list(ret))
内置函数map
str = ['a', 'd', 'b']
def fansik(num):
return num + "fansik"
ret = map(fansik, str)
print(ret)
print(list(ret))
内置函数reduce
from functools import reduce
def add1(x, y):
return x + y
print(reduce(add1, range(1, 101)))
内置函数lambda
from functools import reduce
print(reduce(lambda x, y: x + y, range(1, 101)))