一つの要素のみからなるtuple型をリテラルで定義する方法は以下である。
a = (1,)
print(type(a))
# "()"無しでも可能
a = 1,
print(type(a))
<class 'tuple'>
<class 'tuple'>
ただ単に()
で記述した場合はタプル型にはならない。
a = (5)
print(type(a))
<class 'int'>
また、要素数が0のtuple型を作成する方法は以下である。
a = ()
print(type(a))
<class 'tuple'>
公式ドキュメント
https://docs.python.org/ja/3/library/stdtypes.html#tuple