天天看點

python學習 Day04

python學習 Day05

元組,基本與清單類似, 現在同時還有别的事在做,是以一天也學不了很多(哭)。

#author: Cao Zhanxiang
#time: 2020/7/5
#function: 元組

# 與清單類似,隻是元組元素不能修改,也就是建立後隻讀

tuple1 = (1, 'a', 2, "b")
print(tuple1)
tuple2 = ()     # 空元組
print(tuple2)


# 元組不可變
# 元組不可變指的是變量名綁定的對象不可變,但不是變量名不可與其他對象綁定
tuple1 = (1, 2)     # 這樣是可行的
print(tuple1)
# tuple1[0] = 2     # 這樣是不行的


# 其他操作均與清單相似