Python Empty Tuple
You can create an empty tuple in Python in two ways. The first one providing no elements in the parenthesis, and the second is providing no iterable to the tuple() builtin function.
You can check if the Tuple is empty or not by finding its length. Length of an empty tuple is zero.
Create Empty Tuple using Parenthesis
In the following example, we will create an empty tuple using opening and closing parenthesis with no items in it.
tupleX = ()
Create Empty Tuple using tuple()
tuple() is a builtin function that creates tuple from an iterable. If you provide nothing to this function, it returns an empty tuple.
tupleX = tuple()
Check if Tuple is Empty
len() builtin function, with the tuple as argument, returns length of the tuple. If the length is zero, then then tuple is empty. Else not.
tupleX = () if len(tupleX) == 0: print('Tuple is empty.')
Tuple is empty.
In this tutorial of Python Examples, we learned how to create an empty Tuple.