元组:
1 # 元组,元素不可被修改,不能被增加或者删除 2 # tuple 3 # tu = (11,22,33,44,) 4 # tu.count(22),获取指定元素在元组中出现的次数 5 # tu.index(22) 6 # 1. 书写格式 7 # tu = (111,"alex",(11,22),[(33,44)],True,33,44,) 8 # 一般写元组的时候,推荐在最后加入 , 9 # 元素不可被修改,不能被增加或者删除 10 # 2. 索引 11 # v = tu[0] 12 # print(v) 13 14 # 3. 切片 15 # v = tu[0:2] 16 # print(v) 17 18 # 4. 可以被for循环,可迭代对象 19 # for item in tu: 20 # print(item) 21 22 # 5. 转换 23 s = "asdfasdf0" 24 li = ["asdf","asdfasdf"] 25 tu = ("asdf","asdf",) 26 27 # v = tuple(s) 28 # print(v) 29 30 # v = tuple(li) 31 # print(v) 32 33 # v = list(tu) 34 # print(v) 35 36 # v = "_".join(tu) 37 # print(v) 38 39 # li = ["asdf","asdfasdf"] 40 # li.extend((11,22,33,)) 41 # print(li) 42 43 # 6.元组的一级元素不可修改/删除/增加 44 tu = (111,"alex",(11,22),[(33,44)],True,33,44,) 45 # # 元组,有序。 46 # v = tu[3][0][0] 47 # print(v) 48 # v=tu[3] 49 # print(v) 50 tu[3][0] = 567 51 print(tu)