Python附加字典,TypeError:无法散列的类型? [英] Python appending dictionary, TypeError: unhashable type?

查看:91
本文介绍了Python附加字典,TypeError:无法散列的类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

abc = {}
abc[int: anotherint]

然后出现错误. TypeError:无法散列的类型?我为什么收到这个? 我已经尝试过str()

Then the error came up. TypeError: unhashable type? Why I received this? I've tried str()

推荐答案

这似乎是语法问题:

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

至少以下语法不正确

abc[int: anotherint]

我想你想说

abc = [int: anotherint]

这也是不正确的.正确的方法是

Which is incorrect too. The correct way is

abc = {int: anotherint}

除非已经定义了abc,否则:

unless abc is already defined in which case:

abc[int] = anotherint

也是有效的选项.

这篇关于Python附加字典,TypeError:无法散列的类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆