# 元组 tuple,元素不可被修改,不能被增加或则删除标签:12,22,Python,44,tu,元组,33,print From: https://www.cnblogs.com/liu-zhijun/p/18340596
tu = (111, 'alex', (11, 22), [(33, 44)], True, 33, 44,)
# 一般写元组的时候,最后可以加个逗号不报错
print(tu)
tu = (111, 'alex', (11, 22), [(33, 44)], True, 33, 44,)
v = tu[0] # 元组索引
print(v)
tu = (111, 'alex', (11, 22), [(33, 44)], True, 33, 44,)
v = tu[0:2] # 元组切片
print(v)
tu = (111, 'alex', (11, 22), [(33, 44)], True, 33, 44,)
for item in tu: # 元组可以被for循环,元组可迭代对象,是有序的
print(item)
s = 'ewifjw5'
li = ['fdoe', 2135]
tu = (123, 980, 'odje')
v = tuple(s) # 字符串转换成元组
v2 = tuple(li) # 列表转换成元组
v3 = list(tu) # 元组转出列表
print(v, -5)
print(v2)
print(v3,9)
tu = ('fdsfq', 'odje')
v='_'.join(tu) #如果有数字则不行,得自己写for循环
print(v)
li=['adfaf','fwifawf']
li.extend((11,22,33,))
print(li)
tu = (111, 'alex', (11, 22), [(33, 44)], True, 33, 44,)
v=tu[3][0][0]
print(v)
tu = (111, 'alex', (11, 22), [(33, 44)], True, 33, 44,)
tu[3][0]=567 #元组的一级元素不可修改/删除/增加,但是里面二级列表的元素可以修改
print(tu)
tu=(11,22,33,44) #获取指定元素在元组中出现的次数
tu.count(22)
print(tu)
v=tu.index(22)
print(v)