5-2 取用部分tuple內容
Last updated
Last updated
t = (1, 2, 5, 3, 6)
t2 = t[1:4] #從索引值1開始, 一直到4之前(不包括4)
print(t2)
print(type(t2))(2, 5, 3)
<class 'tuple'>t = (1, 2, 5, 3, 6)
t2 = t[-1] #取出最後一個值
print(t2)
print(type(t2))
t3 = t[4] #也是取出最後一個值
print(t3)6
<class 'int'>
6