1、格式
(資料1,資料2,資料3,...)
定義元組使用小括號,且逗號隔開各個資料,資料可以是不同的資料型別,
元組和串列的區別:元組存盤的資料不能修改
2、定義的型別
單資料元組和多資料元組
t1 = (1, 2) print(type(t1)) # tuple 多資料元組 t2 = (1,) print(type(t2)) # tuple 單資料元組 t3 = (1) print(type(t3)) # int 沒有逗號,就是資料本身的型別 l1 = [1,2] print(type(t3)) # list 串列 l2 = [1] print(type(t3)) # list 串列
3、常用函式
|
查找 |
|
|
修改 |
t1 = (1, 2, [31, 32])
# t[0]=3 報錯
t1[2][0] = 3 #修改的串列內的資料,不報錯
print(t1)
|
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/187333.html
標籤:Python
上一篇:python(遞回函式)
