gpt4 book ai didi

python - 为什么不能删除 python 3 中的字典?

转载 作者:行者123 更新时间:2023-11-28 19:04:06 24 4
gpt4 key购买 nike

我在python 3中创建了一个dict,它的类型是预期的dict,

dict = {'Name': 'Tom', 'Age': 7, 'Class': 'First'}
type(dict)

然后我用del删除了它,但它仍然存在并且type被更改为“type”

del dict       # delete entire dictionary
type(dict)

为什么 del 对 dict 不起作用?为什么类型改变了?

最佳答案

当您将字典命名为 dict 时出现问题。

dict 是内置函数。

重命名字典并重试:

dict1 = {'Name': 'Tom', 'Age': 7, 'Class': 'First'}
type(dict1)
del dict1
dict1

关于python - 为什么不能删除 python 3 中的字典?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48957308/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com