# some basic tuple examples. l = (10,20,30) m = (30,20,10) print(f"l: {l}") print(f"m: {m}") print(f"m[0]: {m[0]}") print(f"m[1]: {m[1]}") print(f"m[2]: {m[2]}") print(f"l==m: {l==m}") print(f"l==[10,20,30]: {l==[10,20,30]}") # no need to know for the moment: lexicographical comparison on lists. print(f"l>m: {l>m}") print(f"m>l: {m>l}") """ Methods changing lists do not exist for tuples. E.g., # append: add to the end. print(l.append(20) l.append(30) l.append(20)) l.append(20) l.append(30) l.append(20) """ print(f"l: {l}") print(f"len(l): {len(l)}") print(f"l.count(20): {l.count(20)}") print(f"l+m:{l+m}") p = (1, 'hello', 1.89e40, (3+10, 'world')) print(f"p: {p}") print(f"p[0]: {p[0]}") print(f"p[1]: {p[1]}") print(f"p[2]: {p[2]}") print(f"p[3]: {p[3]}") print(f"p[3][0]: {p[3][0]}") print(f"p[3][1]: {p[3][1]}") q = (10,20,30) print("tuples are immutable") print(f"q: {q}") print(f"id(q): {id(q)}") print( """ql = list(q) ql.reverse() ql.append(90) q = tuple(ql)""") print("If really, really need to change a tuple, convert it to a list.") ql = list(q) ql.reverse() ql.append(90) q = tuple(ql) print(f"q: {q}") print(f"id(q): {id(q)}")