Create an empty Tuple
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.
1. 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.
Python Program
x = ()
print(x)
2. 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.
Python Program
x = tuple()
print(x)
3. Check if Tuple is Empty
You can check if the created tuple is empty using len() function. 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.
Python Program
x = ()
if len(x) == 0:
print('Tuple is empty.')
Output
Tuple is empty.
Summary
In this tutorial of Python Examples, we learned how to create an empty Tuple.