Discuss / Python / 交作业

交作业

Topic source

骤然跌落

#1 Created at ... [Delete] [Delete and Lock User]

a=(1,2,3) b=(1,[2,3]) d0={'a0':a} d0['a0'] (1, 2, 3) s0=set(a) s0 {1, 2, 3} d1={'b0':b} d1['b0'] (1, [2, 3]) d2={b:'b1'} Traceback (most recent call last): File "", line 1, in TypeError: unhashable type: 'list' s1=set(b) Traceback (most recent call last): File "", line 1, in TypeError: unhashable type: 'list' d3={a:'a1'} d3[a] 'a1'

结论:在dict中,list不能用作key,但可以作为value;在set中,因为仅有key,没有value,所以不能包含list


  • 1

Reply