gpt4 book ai didi

Python追加字典,TypeError : unhashable type?

转载 作者:太空狗 更新时间:2023-10-29 21:30:02 24 4
gpt4 key购买 nike

abc = {}
abc[int: anotherint]

然后错误就来了。类型错误:不可散列的类型?为什么我收到这个?我试过 str()

最佳答案

这似乎是一个语法问题:

>>> abc = {}
>>> abc[1] = 2
>>> abc
{1: 2}
>>> abc = {1:2, 3:4}
>>> abc
{1: 2, 3: 4}
>>>

至少下面的语法是错误的

abc[int: anotherint]

我猜你想说

abc = [int: anotherint]

这也是不正确的。正确的做法是

abc = {int: anotherint}

除非 abc 已经定义,在这种情况下:

abc[int] = anotherint

也是一个有效的选项。

关于Python追加字典,TypeError : unhashable type?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3929234/

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