目录python
s = 'python' L = tuple(s) L ('p', 'y', 't', 'h', 'o', 'n')
l = ('p', 'y', 't', 'h', 'o', 'n') l type(l) ('p', 'y', 't', 'h', 'o', 'n') tuple
只含有一个元素的元组的定义,后面必须加一个逗号
t = (1,)code
与列表一致对象
语法:元组[start:stop:step]索引
Examples:it
tuple1 = ('life', 'is', 'short', 'I', 'use', 'python', 'python') tuple1.count('python') 2
Examples:class
tuple1 = ('life', 'is', 'short', 'I', 'use', 'python', 'python') tuple1.index('python') 5
元组的不可变是指,元组自己本身的元素不可变,同理列表可变是指列表本身自己的元素可变。
元组内部对象为列表时,列表可改数据类型