Discuss / Python / tuple虽然是不变对象,但试试把(1, 2, 3)和(1, [2, 3])放入dict或set中,并解释结果

tuple虽然是不变对象,但试试把(1, 2, 3)和(1, [2, 3])放入dict或set中,并解释结果

Topic source

维他命_心

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

把(1,2,3)放到set里都报错了,有大神可以解释下吗?

>>> s=set([1,2(1,2,3)])

<stdin>:1: SyntaxWarning: 'int' object is not callable; perhaps you missed a comma?

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

TypeError: 'int' object is not callable

你漏敲了一个逗号啦!改成这个就可以啦!

s=set([1,2,(1,2,3)])

维他命_心

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

天,这我都没发现...感谢感谢!


  • 1

Reply