+1 vote
in Programming Languages by (12k points)
How to declare a tuple containing 0 or 1 items?

1 Answer

0 votes
by (21.5k points)

To declare a tuple containing 0 items, use an empty pair of parentheses.

To declare a tuple containing 1 item, put a comma after a value.

E.g.

>>> a=()
>>> b='test',    # note trailing comma
>>> len(a)
0
>>> len(b)
1

...