≮Python≯

タプルの要素が1つの時は要素の着後に , を付ける。

付けないと ) が数値演算の優先度を決めるカッコになる!

t = (1)
print(t[0]) #エラー

t = (1, )
print(t[0]) #正常に表示
#Python #プログラミング
画像1