【发布时间】:2020-09-16 01:04:52
【问题描述】:
有人可以向我解释一下 python 中的 print 命令是如何订购一个集合的吗?我知道集合的顺序是随机的,但是如果我通过名称或打印命令调用集合,为什么会得到不同的输出?例如:
test = {1,32,0,5,84,9}
test有输出 {0, 1, 5, 9, 32, 84}
但
print(test)
有输出 {32, 1, 0, 5, 9, 84}
感谢您的回答!
【问题讨论】:
-
test has the output {0, 1, 5, 9, 32, 84}是什么意思?原因打印(测试)has it's order -
您不能订购一套。查看this answer 了解更多信息。
-
是的,我知道我不能订购它。但问题是为什么当我使用 print 命令时会得到不同的输出?
标签: python printing set output