''''''
'''
元组类型:
在()内,可以存放多个类型的值,并以逗号隔开
注意:
元组与列表不一样的是,只能在定义时初始化值,不能对其进行修改
优点:
在内存中占用资源比列表小
'''
#元组定义:
tuple1 = (1,2,3,'五','六') #本质是tuple((1,2,3,'五','六'))
print(tuple1) #(1, 2, 3, '五', '六')
'''
优先掌握的操作:
1、按索引取值(正向取+反向取):只能取
2、切片(顾头不顾尾,步长)
3、长度len
4、成员运算in和not in
5、循环for
'''
#1、按索引取值(正向取+反向取):只能取
print(tuple1[2]) #3
#2、切片(顾头不顾尾,步长)
#从0开始切片到5-1,步长为3
print(tuple1[0:5:3]) #(1, '五')
#3、长度len
print(len(tuple1)) #5
#4、成员运算in和not in
print(1 in tuple1) #True
print(1 not in tuple1) #False
#5、循环for
for line in tuple1:
#默认换行
print(line)
#不换行
print(line,end = ' ') #1 2 3 五 六