常用如下所示:

# 元祖,tuple-->不可变,但元祖里面的数据可以变化

# 当元祖只有一个元素时,需加’,‘,否则类型是<class 'int'>
# tuple1 = (1)
# print(type(tuple1)) tuple1 = (1,2,3,4,[2,3,5,6],{'name':"huang"})
# print(dir(tuple1)) # count-->计数
# print(tuple1.count(2)) # index --->索引
# print(tuple1.index(4)) # 把元祖的列表由[2,3,5,6]修改为[2,3,5,6,7]
# tuple1[4].insert(4,7)
# print(tuple1) #把元祖中字典的name修改为hu
tuple1[5]['name']='hu'
print(tuple1)
05-11 09:39