元组 集合
# 什么是元组: 元组就是一个不可变的列表# ======================================基本使用======================================# 1、用途: 用于存放多个值,当存放的多个值只有读的需求没有改的需求时用元组最合适# 2、定义方式:在()内用逗号分隔开多个任意类型的值t=(1,3.1,'aaa',(1,2,3),['a','b']) # t=tuple(...)# print(type(t))# res=tuple('hello')# res=tuple({'x':1,'y':2})# print(res)# 3、常用操作+内置的方法#优先掌握的操作:#1、按索引取值(正向取+反向取):只能取# t=('a','b',1)# t[0]=111#2、切片(顾头不顾尾,步长)# t=('h','e','l','l','o')# res=t[1:3]# print(res)# print(t)#3、长度# t=('h','e','l','l','o')# print(len(t))#4、成员运算in和not in# t=('h','e','l','l','o')# print('h' in t)#5、循环# t=('h','e','l','l','o')# for item in t:# print(item)#