Python中文
首页
教程
问答
标签
搜索
登录
注册
在Python中,对象可以用作字典中的键吗?
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我有一些令人费解的代码,我正试图迁移到Typescript。看看这个:</p> <pre><code> def add_Octopus(self, code, cracker, fate, description, arm_number, ink_content, fate_pointer, churlishness=None): self.special_octopoda[ Octopus(code, description, arm_number, fate, churlishness, self, ink_content, fate_pointer)] = fate_pointer, cracker </code></pre> <p>在我看来,好像章鱼对象被用作一个名为special\ octopoda的字典中的键。Python允许这样做吗?当然不是在Typescript/Javascript中。你知道吗</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>在python中,只有不可变类型可以用作键。对于可能的解决方法,请将其包装为元组:</p> <pre><code>self.special_octopoda(<something>, Octopus(...)) </code></pre> <p>或者使您的类可散列:</p> <pre><code>class Octopus: def __hash__(self): # hash implementation </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何将python输出重定向到python控制台和Windows中的文本文件
5 回答
如何将Python运行时嵌入运行在Windows上的R包中
1 回答
如何将python进程作为另一个Windows us运行
4 回答
如何将Python进程的输出用Python管道传输?
7 回答
如何将Python进程的输出重定向到Rust进程?
10 回答
如何将python连接到Azure云并创建Azure数据工厂
1 回答
如何将Python连接到Db2
1 回答
如何将python连接到IBMDB2?
8 回答
如何将Python连接到microsoftaccess数据库文件?
6 回答
如何将python连接到MySQL服务器
8 回答
如何将Python连接到Node.js?
10 回答
如何将python连接到Oracle Application Express
8 回答
如何将Python连接到PostgreSQL
1 回答
如何将Python连接到Postgres服务器?
10 回答
如何将Python连接到SAS Enterprise Guide(EG)服务器
8 回答
如何将Python连接到Spark会话并保持RDDs的Ali
2 回答
如何将python连接到sqlite3并在上填充多行
5 回答
如何将python连接到使用docker运行的cassandra
3 回答
如何将python退格应用于字符串
7 回答
如何将python逻辑应用到tkinter GUI中?这是一个简单的GET请求程序
10 回答