Python 學習筆記

list 的格式 a=['a','b','c']對象

tuple 的格式 a=('a','b','c')排序

dict 的格式 a={a:b}--b能夠省略 a不能爲listhash

set 的格式 a=set((a))--a不能爲listast

a=(1,2,3)module

b=(1, [2, 3])call

c={a} {(1, 2, 3)} 這裏(1,2,3)應該是一個總體的key值dict

d={b}di

Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unhashable type: 'list'ab

dict 的key必須爲不可變對象。而 b中的[2,3]可變因此報錯。

e={a:b}

{(1, 2, 3): (1, [2, 3])}

e[a]

(1, [2, 3])

dict 的key必須爲不可變對象。這裏將key變成了不可變對象。value是否可變無影響。

b[1][0]=3

e

{(1, 2, 3): (1, [3, 3])}

f=set(a)

{1, 2, 3} 這裏1,2,3表示有這三個元素,即便是顯示結果排序了,也不表示set是有序的。

g=set(b) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unhashable type: 'list'

set 的key必須爲不可變對象。而 b中的[2,3]可變因此報錯。

相關文章
相關標籤/搜索