Tuples

Is a Tuple {} or () in Python?

() makes an empty tuple in Python, while {} makes an empty dictionary. Learn why the comma matters and how set() differs, with short examples.

On this page
  1. The short answer
  2. Why the comma makes the tuple
  3. Why {} is a dictionary
  4. The same question in C++
  5. Quick summary

The short answer

() is an empty tuple. {} is an empty dictionary, not a tuple. Python uses braces for dictionaries and sets, and parentheses for tuples. The comma is what makes a tuple, so parentheses are optional for a tuple with items but required for the empty one.

print(type(()))     # <class 'tuple'>
print(type({}))     # <class 'dict'>
print(type(set()))  # <class 'set'>

Why the comma makes the tuple

Parentheses also group expressions, which makes them easy to misread. For a tuple with one item, the trailing comma is required:

single = (5)     # just the integer 5
pair = (5,)      # a tuple with one item
nums = 1, 2, 3   # a tuple without parentheses

The first line gives an integer, because the parentheses only group the 5. The other two lines create tuples.

Why {} is a dictionary

Braces with key-value pairs create a dictionary, and empty braces are read as an empty dictionary:

ages = {"Ada": 36}  # a dictionary
empty = {}          # also a dictionary, not a tuple

To make an empty set, use set(). Readers who ask “Is set() the same as {}?” run into the same confusion. The answer is no: {} is an empty dictionary, while set() is the empty set.

The same question in C++

C++ has no rule that braces mean a dictionary. Braces mean brace initialization there, and they can build an empty tuple as well as a tuple with values:

#include <tuple>

std::tuple<> nothing{};                  // an empty tuple
std::tuple<int, double> values{1, 2.5};  // a tuple with two values

Quick summary

  • () is an empty tuple.
  • (5,) is a tuple with one item, while (5) is just the number 5.
  • {} is an empty dictionary.
  • set() is an empty set.

For a quick look at tuples in general, see “What is a tuple and list?”

The complete guide to tuples

Tuples in C++ With std::tuple
Read the guide

Keep exploring

Guides from other topics

All topics →

Inheritance in C++

A practical guide to inheritance in C++: the syntax, access specifiers, constructor order, virtual functions and common mistakes, with short code examples.

Inheritance 7 min read