解决object at 0x01DB75F0
python在学习过程中吗,由于常常会出现代码运行没报错,但输出的却不是我们想要的结果(图表,列表等等),而出现类似
<filter object at 0x01DB75F0>的情况,比如:
def is_odd(x): return x % 2 == 1 print((filter(is_odd,[1,3,5,6,7])))
输出:
<filter object at 0x01DB75F0>
Process finished with exit code 0
这是因为访问对象时,返回的是一个地址,不是真实的数据 !
此时只需在外层加个list即可
def is_odd(x): return x % 2 == 1 print(list(filter(is_odd,[1,3,5,6,7])))
此时输出:
[1, 3, 5, 7]
Process finished with exit code 0