美文网首页
python 基础

python 基础

作者: RICKYMAN | 来源:发表于2018-10-30 18:11 被阅读0次

1030

>>> b
[1, 3, [1, 2], [1, 2]]
>>> list(b)
[1, 3, [1, 2], [1, 2]]
>>> set(b)
Traceback (most recent call last):
  File "<pyshell#38>", line 1, in <module>
    set(b)
TypeError: unhashable type: 'list'

原因:set 用hash计算的,因此元素不可变,但是列表是可变的

相关文章

网友评论

      本文标题:python 基础

      本文链接:https://www.haomeiwen.com/subject/lhfntqtx.html