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

相关文章:

  • 2021-12-01
  • 2022-12-23
  • 2021-12-28
  • 2021-06-14
  • 2021-12-11
  • 2021-06-26
  • 2021-07-11
猜你喜欢
  • 2022-02-24
  • 2021-12-19
  • 2022-12-23
  • 2022-01-18
  • 2022-12-23
  • 2021-06-29
  • 2021-04-02
相关资源
相似解决方案