t = (11, 22, 33, 'python', 44, 55, 66) print(t[0]) # 11 print(t[1:3]) # (22, 33) for i in t: print(i) # 11 22 33 python 44 55 66 t = (1,) print(type(t)) # <class 'tuple'> t = (1) print(type(t)) # <class 'int'>
元組的不可變指的是元組內第一層元素的內存地址不可變python
t = (11, 22, 33, [], 44) t[3] = [55,] # 報錯 t[3].append(55) # (11, 22, 33, [55], 44)
元組也有count, index, len等方法app