Python Empty Tuple | Explained

In Python, the tuple data structure stores multiple collections of data elements. All the tuple items have an ordered sequence that allows duplicates and are immutable. We can not modify the tuple after creating it, unlike a list. A tuple value is initialized inside the parenthesis and follows the comma-separated syntax, such as “(4,5,6,7)” is the tuple containing four elements.

An empty tuple means no item/element value is inside the parentheses. Using the below-listed contents, an in-depth overview of Python’s empty tuples is explained with numerous examples:

Let’s begin!

What is an Empty Tuple in Python?

An empty tuple means no element is inside the parentheses, i.e., “( )”. In Python, an empty tuple has a length equal to “zero”. An empty tuple is created in Python using the inbuilt “tuple()” function and empty pair of parentheses. The syntax of the tuple() is shown below:

tuple(iterable)

The parameter “iterable” takes a list, dictionary, range, etc., and returns the corresponding tuple. But if none of the values is passed inside the parentheses, then an empty tuple is created.

Let’s create an empty tuple using the following examples:

Example 1: Python Empty Tuple Using tuple() Function

In the following example, the inbuilt “tuple()” function is utilized to create an empty Python tuple.

Code:

tuple_empty = tuple()

print("\n Empty Tuple Created: ",tuple_empty)
print('\n Checking Data Type: ', type(tuple_empty))
print('\n Checking length of Tuple:', len(tuple_empty))

In the above code:

  • The empty tuple is created using the inbuilt “tuple()” function.
  • The “tuple()” function takes an iterable object as an argument, but if we do not pass any value, then an empty tuple will be created.
  • The “type()” and “len()” functions are used to verify the data type and length of the empty tuple.

Output:

An empty tuple is created in the above output.

Example 2: Python Empty Tuple Using Blank Parenthesis

In the example below, an empty tuple is created using blank parentheses. Blank parentheses mean no items lying between the opening and closing parentheses.

Code:

tuple_empty = ()

print("\n Empty Tuple Created: ",tuple_empty)
print('\n Checking Data Type: ', type(tuple_empty))
print('\n Checking length of Tuple:', len(tuple_empty))

In the above example code:

  • The empty Python tuple is created using only empty parentheses.
  • The empty parentheses or empty tuple is stored in a variable named “tuple_empty”.
  • The “type()” and “len()” function is used to verify the data type and length of the empty tuple.

Output:

In the above output, the empty tuple is created.

That’s all from this Python Guide!

Conclusion

To create an empty tuple, the inbuilt “tuple()” function and empty parenthesis “( )” are used in Python. Empty parentheses mean that there are no items between the parentheses. The “len()” function is used to check the length of the empty tuple, which is always “zero”. This article demonstrated different ways of creating empty tuples in Python with examples.