好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

python3中内置函数介绍

在python3 中,filter、map、reduce已经不是内置函数,即<build-in function>,python3中三者是class,返回结果变成了可迭代的对象

1.filter(function,iterable)

通过function过滤条件,去获取 iterable 中你想要的数据。

from collections import Iterator
test_list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
f = filter(lambda x: x % 3 == 0, test_list)
# filter 得到的是一个迭代器

print(isinstance(f, Iterator))
f.__next__()

for i in f:
    print(i)

# 
输出 True 6 9

查看更多关于python3中内置函数介绍的详细内容...

  阅读:47次