元祖 -- (tuple)

 Python的元组与列表类似,不同之处在于元组的元素不能修改(只读列表,显示儿子级别的增删改)。
 元组使用小括号,列表使用方括号。
 元组创建很简单,只需要在括号中添加元素,并使用逗号隔开即可。
 
 实例:
 tuple1 = ('physics', 'chemistry', 1997, 2000);
 tuple2 = (1, 2, 3, 4, 5 );
 tuple3 = "a", "b", "c", "d";
  
 元祖中包含一个元素时,需要在元素后面添加逗号
 tuple = (50,);
 
 切片:
 实例:
 >>> tuple1
 ('physics', 'chemistry', 1997, 2000)
 >>> tuple1[0]
 'physics'
 >>> tuple1[:2]
 ('physics', 'chemistry')
 >>> tuple1[::2]
 ('physics', 1997)
 
 查看:
 >>> tuple4
 ('physics', 'chemistry', 1997, 2000, 1, 2, 3, 4, 5)
 >>> for i in tuple4: print(i)
 physics
 chemistry
 1997
 2000
 1
 2
 3
 4
 5
  
 元祖的运算符
 表达式       结果       描述
 len((1, 2, 3))     3        计算元素个数
 (1, 2, 3) + (4, 5, 6)   (1, 2, 3, 4, 5, 6)    连接
 ('Hi!',) * 4     ('Hi!', 'Hi!', 'Hi!', 'Hi!') 复制
 3 in (1, 2, 3)     True       元素是否存在
 for x in (1, 2, 3): print x, 1 2        迭代

原文地址:https://www.cnblogs.com/liwei-python-21/p/8778468.html