小编par*_*t15的帖子

布尔作为字典中的键会导致奇怪的问题吗?

我是 Python 新手,目前正在学习字典。我将随机值和类型放入字典中。这是让我困惑的地方:

stuff = {True: 1234, 1: 2}
print(stuff[True])
print(len(stuff))
Run Code Online (Sandbox Code Playgroud)

当您运行这段代码时,输​​出是:

2
1
Run Code Online (Sandbox Code Playgroud)

这是怎样的输出?不应该print(stuff[True])输出1234print(len(stuff))正在输出吗2?我可能会遗漏一些非常明显的东西,但是有人可以解释一下发生了什么吗?

python dictionary

5
推荐指数
1
解决办法
517
查看次数

标签 统计

dictionary ×1

python ×1