IndexError: tuple index out of range
索引错误:元组的索引超出范围
三、切片
元组的切片与列表相同,只包括起始位置,不包括结束位置。
tuple1[0:2]
(1, 2)
当切片时起始位置超出索引范围时,会返回一个空元组。
tuple1[5:]
()
四、元组的方法
由于元组不可修改,所以元组的方法非常少。
1.count 统计元素出现的次数,返回一个整数
T.count(value) -> integer -- return number of occurrences of value
tuple1.count(1)
1
2.index 查找某个元素的索引位置
T.index(value, [start, [stop]]) -> integer -- return first index of value. Raises ValueError if the value is not present.
tuple1.index(2)
1
五、元组与列表的转换
1元组转换为列表
print tuple1