タプル型は、イミュータブルimmutableで要素の値が変更できません。
tp = (10,20,30)
print("tp[0] = ", tp[0])
print("tp = ", tp)
# tp[0] = 50 エラーが起きる。タプルの値は変更できない。
tp2 = ([11, 22, 33],[55, 66, 77])
print("tp2 = ", tp2)
dlist = [100, 200, 300]
tp3 = tuple(dlist) #リストをタプル型に変換する
print("tp3 = ", tp3)
a = 50
b = 150
c = '250'
d = (a, b, c) #タプルパッキング
e, f, g = d #アンパッキング
print("e = ", e)
print("f = ", f)
print("g = ", g)
出力結果は続きを….
【出力結果】
tp[0] = 10
tp = (10, 20, 30)
tp2 = ([11, 22, 33], [55, 66, 77])
tp3 = (100, 200, 300)
e = 50
f = 150
g = 250