Python设置不为空但pop返回空?
我在多线程中看到了类似的问题,但这甚至不是多线程,它只是直接填充一个集合然后弹出。
我打印出该集合,然后立即尝试打印该集合的流行音乐。但当我看到类似这样的集合打印输出时,它说集合是空的:
set(['', 'asdf', 'asdf, 'asdf'])
I saw a similar problem with multithreading but this isn't even multithreading, it's just straight up populating a set and then popping.
I print out the set and then immediately after, try to print out the pop of the set. but it says the set is empty when i see something like this for the set print out:
set(['', 'asdf', 'asdf, 'asdf'])
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您的集合中有一个空字符串,因此
foo.pop()
很可能返回该空字符串,并且打印空字符串不会给您带来任何结果。Since you have an empty string in your set, it is highly possible that a
foo.pop()
returns this empty string and printing an empty string gives you nothing.