Discuss / Python / 想法

想法

Topic source

Zayn_______

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

t = (1, 2, 3) s = set(t) d = {'tuple' : t}

相当于将tuple这个变量所指向的值依次注入set或dic中 这时set的值add,remove都不会影响tuple

t= (1, 2, [3, 4]) s = set(t) dic = @{t : 'tuple'} 报错 unhashable type: 'list' 因为set和dic的存储方式都是哈希算法,通过key来查找value 所以key必须存储不可变类型,否则内部结构会混乱,无法查找value的值


  • 1

Reply