- 元组有两种定义方式
#元组的两种定义方法
a_tuple = (1,2,30,30,4,5)
b_tuple = 1,2,30,30,4,5
print(a_tuple)
print(b_tuple)
out:(1, 2, 30, 30, 4, 5)
(1, 2, 30, 30, 4, 5)
print(a_tuple[1])
out:2
print(a_tuple[1:4])
out:(2, 30, 30)
print(a_tuple.count(30))
out:2
for i in a_tuple:
print(i)
out:
1
2
30
30
4
5
#基本上与列表一样
-
元组里面的值不能修改(排序,增加,减少)
-
元组想修改,只可以重新赋值
a_tuple = (1,2,3,4)
print(a_tuple)
out:(1, 2, 3, 4)