tuple裡面可以在使用更多的tuple
例如
#tuple.py
location = ("taipei",101,("信義區","大安區","中正區"))
print(location)
print(location[2][1])
print(location[2][1][1])
Python可借由tuple unpacked快速的實現變數交換
例如
#tuple.py
a=3
b=4
a,b=b,a # 或寫成(a,b)=(b,a)
print(a)
print(b)
也可以運用在for...in中
例如
#tuple.py
for x,y,z in ((1,2,3),(3,4,5),(5,6,7)):
print(x+y+z)