In this tutorial, we will look at how to check if a tuple is empty or not in Python with the help of some examples.

## How to check if a tuple is empty?

Tuples are ordered collections of items (that are immutable) in Python. A tuple is empty if it does not contain any item. You can use the following methods to check if a tuple is empty or not in Python.

- Using the
`len()`

function. - Comparing the tuple with an empty tuple.
- Using the tuple in a boolean context.

Let’s now take a look at each of the above methods with the help of some examples.

### Using the `len()`

function

The length of an empty tuple is zero.

You can use the Python `len()`

function to calculate the length of the tuple and then compare it with zero to check if it is empty or not. Here’s an example –

# create two tuples - t1 is empty and t2 is non-empty t1 = () t2 = (1, 2, 3) # check if tuple is empty print(len(t1)==0) print(len(t2)==0)

Output:

True False

We get `True`

as the output for the tuple `t1`

as it is empty and `False`

for the tuple `t2`

because it’s not empty (has non-zero length).

### Comparing the tuple with an empty tuple

You can also check if a tuple is empty or not by comparing it with an empty tuple using the `==`

operator. Let’s look at an example.

**Data Science Programs By Skill Level**

**Introductory** ⭐

- Harvard University Data Science: Learn R Basics for Data Science
- Standford University Data Science: Introduction to Machine Learning
- UC Davis Data Science: Learn SQL Basics for Data Science
- IBM Data Science: Professional Certificate in Data Science
- IBM Data Analysis: Professional Certificate in Data Analytics
- Google Data Analysis: Professional Certificate in Data Analytics
- IBM Data Science: Professional Certificate in Python Data Science
- IBM Data Engineering Fundamentals: Python Basics for Data Science

**Intermediate ⭐⭐⭐**

- Harvard University Learning Python for Data Science: Introduction to Data Science with Python
- Harvard University Computer Science Courses: Using Python for Research
- IBM Python Data Science: Visualizing Data with Python
- DeepLearning.AI Data Science and Machine Learning: Deep Learning Specialization

**Advanced ⭐⭐⭐⭐⭐**

- UC San Diego Data Science: Python for Data Science
- UC San Diego Data Science: Probability and Statistics in Data Science using Python
- Google Data Analysis: Professional Certificate in Advanced Data Analytics
- MIT Statistics and Data Science: Machine Learning with Python - from Linear Models to Deep Learning
- MIT Statistics and Data Science: MicroMasters® Program in Statistics and Data Science

**🔎 Find Data Science Programs 👨💻 111,889 already enrolled**

Disclaimer: Data Science Parichay is reader supported. When you purchase a course through a link on this site, we may earn a small commission at no additional cost to you. Earned commissions help support this website and its team of writers.

# create two tuples - t1 is empty and t2 is non-empty t1 = () t2 = (1, 2, 3) # check if tuple is empty print(t1 == ()) print(t2 == ())

Output:

True False

We get the same results as above.

Note that here we use `()`

without any elements to represent an empty tuple. You can also use the `tuple()`

constructor with default parameters to create an empty tuple.

### Tuple in a boolean context

If you use a tuple in a boolean context, it will evaluate to `True`

if it has any elements and it will evaluate to `False`

if the tuple is empty. Thus, you can use the expression `not t`

to check if the tuple `t`

is empty or not.

Here’s an example.

# create two tuples - t1 is empty and t2 is non-empty t1 = () t2 = (1, 2, 3) # check if tuple is empty print(not t1) print(not t2)

Output:

True False

We get the same result as above. `True`

for the tuple `t1`

as it’s empty and `False`

for the tuple `t2`

as it’s not empty (`t2`

has three elements).

In this tutorial, we looked at three methods to check if a tuple is empty or not. Use the method that you are the most comfortable with.

You might also be interested in –

**Subscribe to our newsletter for more informative guides and tutorials. ****We do not spam and you can opt out any time.**