单元素元组的创建,需要在单元素后面添加一个逗号
tp=("abc") print(type(tp)) tp=("abc",) print(type(tp)) # <class 'str'> <class 'tuple'>多元素元组的创建,包含多种数据类型
(1)拼接
(2)重复
(3)索引(偏移) 切片
tp=("1","2","3") tp2=("a","b","c") print(tp+tp2) print(tp*3) print(tp[:2]) print(tp[:-1]) print(tp[0:3]) # ('1', '2', '3', 'a', 'b', 'c') ('1', '2', '3', '1', '2', '3', '1', '2', '3') ('1', '2') ('1', '2') ('1', '2', '3')索引查
切片查
index()
tp=(1,2,3,"a","b",["aa","bb","cc","dd"]) print(tp.index("a")) # 3max(tp)
min(tp)