Python的元组与列表类似,不同之处在于元组的元素不能修改。元组使用小括号。
1.元组:创建
tup1 = () #创建空元组
tup2 = (50)
tup3 = (50,)
tup4 = (50,60,70)
2.元组:访问
#元组:访问
tup1 = ("abc","def",2000,3000,333,444,555)
print(tup1[0])
print(tup1[-1]) #访问最后一个元素
print(tup1[1:5]) #左闭右开,进行切片
3.元组:增
#元组:增(连接)
tup1 = (12,34,56)
tup2 = ("abc","xyz")
tup = tup1 + tup2
print(tup)
4.元组:删
#元组:删
tup1 = (12,34,56)
print(tup1)
del tup1 #删除了整个元组变量
print("删除后:")
print(tup1)
5.元组:改(不允许)