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计算的,因此元素不可变,但是列表是可变的
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
网友评论