元组是特殊的列表,定义完成后不可以更改
name_tuple=('jack','amy','sam','amy',666,True)
print(type(name_tuple))
name_tuple=('jack')
# 后没加逗号
print(type(name_tuple))
name_tuple=('jack',)
# 后加逗号
print(type(name_tuple))
name_tuple=((1,2,3),(4,5,6))
print(type(name_tuple))
print(name_tuple)
类似列表 元组[下标]
name_tuple=((1,2,3),(4,5,6))
print(name_tuple)
print(type(name_tuple))
print(name_tuple[1])
print(type(name_tuple[1]))
print(name_tuple[1][1])
print(type(name_tuple[1][1]))
与列表类似
name_tuple=(1,2,3,4,5,6)
print(name_tuple)
print(f"2的下标是:{name_tuple.index(2)}")
name_tuple=(1,2,3,4,5,6,2)
print(name_tuple)
print(f"2的个数:{name_tuple.count(2)}")
name_tuple=(1,2,3,4,5,6,2)
print(name_tuple)
print(f"元组元素的个数:{len(name_tuple)}")
与列表一样
name_tuple=(1,2,3,4)
print(name_tuple)
i=0
while i
name_tuple=(1,2,3,[4,5,6])
print(name_tuple)
name_tuple[3][2]=9
print(name_tuple)
name_list=[1,2,3,(4,5,6)]
print(name_list)
print(name_list[3])
name_list[3][2]=9
print(name_list)