1. 声明单个元组需要加逗号,可以不加外面的一对括号
>>> t = (23) //An integer
23
>>> t = (23,) //An tuple containing an integer
(23,)
>>> t = 23, //declare without ()
(23,)
2. 列表转换成元组
>>> List = [1,2,3,4]
>>> T = tuple(List)
>>> List
[1,2,3,4]
>>> T
(1,2,3,4)
3. 元素的顶层对象是不可修改的,但是有下级对象,还素可以修改滴。
>>> T = (1,[1,2],3)
>>> T[1] = 'spam'
TypeError: object doesn't support item assignment
>>> T[1][0] = 'spam'
>>> T
(1, ['spam', 3], 4)