我现在开始学习python,但过滤功能有问题。
如果我跑
list=list(range(10))
def f(x): return x % 2 != 0
print(((filter(f,list))))
我会得到结果是
filter object at 0x00000000028B4E10
Process finished with exit code 0
如果我将代码修改为
list=list(range(10))
def f(x): return x % 2 != 0
print(list(filter(f,list)))
我得到的结果将是
Traceback (most recent call last):
File "C:/Users/Vo Quang Hoa/PycharmProjects/HelloWorld/Hello.py", line 6, in <module>
print(list(filter(f,list)))
TypeError: 'list' object is not callable
Process finished with exit code 1
发生了什么。如何获取列表 1 3 5 7 9 感谢您的帮助。