Python tuple - How to get the length of a tuple

You can get the length of a tuple using the len(), a Python built-in function.

t1 = ('A', 'B', 'C')
t2 = (7,)
t3 = ()

c1 = len(t1)
c2 = len(t2)
c3 = len(t3)

print(c1)  # 3
print(c2)  # 1
print(c3)  # 0

The (7,) needs a trailing comma. Without it, it can't recognized as a tuple. The length of an empty tuple is 0.

Python Tuple

Python Tutorial