Python设置不为空但pop返回空?

发布于 2024-11-07 20:59:05 字数 163 浏览 0 评论 0原文

我在多线程中看到了类似的问题,但这甚至不是多线程,它只是直接填充一个集合然后弹出。

我打印出该集合,然后立即尝试打印该集合的流行音乐。但当我看到类似这样的集合打印输出时,它说集合是空的:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浮生面具三千个 2024-11-14 20:59:05
pop(...)
    Remove and return an arbitrary set element.
    Raises KeyError if the set is empty.

由于您的集合中有一个空字符串,因此 foo.pop() 很可能返回该空字符串,并且打印空字符串不会给您带来任何结果。

pop(...)
    Remove and return an arbitrary set element.
    Raises KeyError if the set is empty.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文