Skip to content
  • (+91) 9409548155
  • support@appdividend.com
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
Menu
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
Python

How to Create and Check an Empty Tuple in Python

  • 26 Mar, 2025
  • Com 0
Creating an empty Tuple and Check if a Tuple is empty in Python

An empty tuple means a tuple without any elements. For example, you can call this “()” an empty tuple. Tuples are written in parentheses; if there are no elements in it, it is just a pair of parentheses with nothing inside.

Empty TupleCreating an empty tuple

The most optimal and fastest approach to create an empty tuple is to use the literal () syntax.

Create an Empty Tuple

# Creating an empty tuple
empty_tuple = ()

print(empty_tuple)
# Output: ()

print(type(empty_tuple)) 
# Output: <class 'tuple'>

It has a widely recognized syntax and minimal overhead.

Using tuple() constructor

Another way is using the tuple() constructor without any arguments. 

Creating an empty tuple using tuple() constructor

# Using the tuple() Constructor
tuple_constructor = tuple()

print(tuple_constructor)
# Output: ()

It is slightly less efficient than “()” because it calls the function, which adds an extra overhead.

However, it is helpful when you have to create a tuple dynamically (e.g., tuple(iterable)), but it is less efficient for empty tuples.

Tuple of empty tuples

The efficient, fastest, and most Pythonic way to create a tuple of empty tuples is to use tuple literals with a trailing comma like this: ((),).

# Create a tuple of an empty tuples
empty_tuples_in_tuple = ((),)

print(empty_tuples_in_tuple)
# Output: ((),)

The above code shows the trailing comma, which explicitly makes it a tuple of one element (an empty tuple).

You can use it as a placeholder in a nested data structure like this:

nested = {"key": ((), "default")}

print(nested["key"])
# Output: ((),)

Tuple of length n with empty-like placeholders (None)

If you want to create pre-defined length empty-like tuples, use the (None,) * n expression where n is a tuple of length.

Pre-allocating a fixed-size tuple

# Creating a Tuple of Length n with empty-like placeholders:
n = 6

empty_placeholders = (None,) * n 

print(empty_placeholders)
# Output: (None, None, None, None, None, None)

It is helpful in pre-allocating a fixed-size tuple.

You can also use empty tuples as place holders like this:

n = 3

tuple_of_empty_tuples = ((),) * n

print(tuple_of_empty_tuples)
# Output: ((), (), ())

How to check if a tuple is empty

The most efficient way to check if a tuple is empty is to use an implicit boolean check using the not operator with an if statement. 

If the tuple is empty, the not operator returns True, meaning it is in fact empty. If it returns False, it is not empty.

Checking if a tuple is empty in Python

empty_tuple = ()

# Implicit Boolean Check
if not empty_tuple:
    print("The tuple is empty")

# Output: The tuple is empty

Since there are no function calls, the time complexity is O(1), which is the fastest. It leverages Python’s __bool__ (or __len__ for sequences) under the hood.

Explicit length check

Another way is to check the length of the tuple. If it is 0, it is empty; otherwise, it is not. You can check the tuple’s length using the len() function.

empty_tuple = ()

# Explicit Boolean Check
empty_tuple = ()

if len(empty_tuple) == 0:
    print("Tuple is empty")

# Output: Tuple is empty

It is a more readable approach, and here, the time complexity is O(1), too, but “not operator” is marginally faster.

Direct comparison

The direct comparison approach is simple and readable because you just need to compare your input tuple with () using the “==” operator like this: if your_tuple == (). However, it is the slowest approach because it creates a temporary tuple, which takes a minor time.

your_tuple = ()

if your_tuple == ():
    print("Tuple is empty")

# Output: Tuple is empty

Checking if a tuple contains an empty tuple

If you want to verify whether a tuple contains an empty tuple, you can use the “in” membership operator.

# Checking If a Tuple Contains an Empty Tuple

main_tuple = ((), "hello", 123)

if () in main_tuple:
    print("Contains an empty tuple")

# Output: Contains an empty tuple

That’s all!

Post Views: 72
Share on:
Krunal Lathiya

With a career spanning over eight years in the field of Computer Science, Krunal’s expertise is rooted in a solid foundation of hands-on experience, complemented by a continuous pursuit of knowledge.

How to Convert Tuple to Frozenset in Python
How to Create and Check an Empty String in Python

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Address: TwinStar, South Block – 1202, 150 Ft Ring Road, Nr. Nana Mauva Circle, Rajkot(360005), Gujarat, India

Call: (+91) 9409548155

Email: support@appdividend.com

Online Platform

  • Pricing
  • Instructors
  • FAQ
  • Refund Policy
  • Support

Links

  • About Us
  • Contact Us
  • Privacy Policy
  • Terms of services

Tutorials

  • Angular
  • React
  • Python
  • Laravel
  • Javascript
Copyright @2024 AppDividend. All Rights Reserved
Appdividend