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

1 Answer

+1 vote
by (349k points)
selected by
 
Best answer

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

Related questions


...