To check whether a tuple is empty in Python, use if not my_tuple:. An empty tuple () is falsy, so the condition is true only when the tuple has no elements. You can also use len(my_tuple) == 0 or my_tuple == (), but the truthiness test is the idiomatic form.
Tuples are immutable, so an empty tuple stays empty for its whole life, and there is only ever one empty tuple object in CPython. The details that cause bugs are the single-element syntax and tuples that contain falsy values.
len()None and nested tuplesPython treats empty containers as False in a boolean context.
To handle the non-empty case, test the tuple directly:
The test is O(1) and also works for lists, sets, dictionaries and strings, so you can reuse it when the container type changes.
len()len() is explicit and equally fast. PEP 8 prefers the implicit boolean test for sequences, but the length form is perfectly valid when you want the number to be visible.
Use == for the comparison. The is result is True in CPython because the empty tuple is a shared singleton, but that is an implementation detail and recent Python versions warn about is with a literal, so do not rely on it.
A tuple is never equal to a list, even if both are empty:
This makes my_tuple == () stricter than not my_tuple. If a function might receive either type, prefer the truthiness test.
A trailing comma, not the parentheses, creates a tuple. Forgetting it produces a different type and breaks emptiness checks.
not_a_tuple is the integer 5, so len(not_a_tuple) would raise TypeError. This is a frequent reason why a "tuple" check behaves oddly.
A tuple is truthy as soon as it has at least one element, even if every element is falsy.
Use not values to test for emptiness. Use any() only when you want to know whether some element is truthy.
None and nested tuplesIf a function can receive None, test for it first when it means something different from an empty tuple.
A nested tuple such as ((),) is not empty, because it holds one element that happens to be an empty tuple. To check that every inner tuple is empty, use not any(inner for inner in outer).
Functions often return an empty tuple to signal "no results", which keeps the return type consistent.
| Method | Example | Notes |
|---|---|---|
| Truthiness | if not t: | Idiomatic, O(1), works for any container |
| Length | if len(t) == 0: | Explicit, O(1) |
| Equality | if t == (): | Strict about type, a list never matches |
any() | if not any(t): | Wrong for emptiness, tests for truthy elements |
Write () or call tuple(). Both give the same empty tuple object.
No, tuples are immutable. You build a new tuple instead, for example t = t + (1,), or collect items in a list and convert it with tuple(items).
(5) not a tuple?Parentheses only group expressions. The comma makes the tuple, so a one-element tuple is written (5,).
len() or truthiness faster?Both are constant time and the difference is negligible. Choose the form that reads best, which is normally the truthiness test.
Use if not my_tuple: to test for an empty tuple, len() when you want an explicit count, and == () only when the type must match exactly. Remember the trailing comma for single-element tuples, and do not confuse an empty tuple with one whose elements are all falsy.