首页 > dict() 元组参数无法创建字典

dict() 元组参数无法创建字典

如图所示,党 dict() 参数为单个(['a',1])或者(('a',1))时,就会出错,但是为[['a',1]]则不会出错,而参数为两个参数,(('a',1),('b',2))则不会出错,十分不解。


当元组只有一个元素的时候,需要加一个,
(('a',1),)为一个嵌套tuple

type((('a',1),))
<class 'tuple'>
type((('a',1),)[0])
<class 'tuple'>

(('a',1)) 为一个tuple值为('a',1)

type((('a',1)))
<class 'tuple'>
type((('a',1))[0])
<class 'str'>

(('a',1),)
【热门文章】
【热门文章】