Content · Programming · Python

Python Single-Element Tuples: Why the Comma Matters

A single-element tuple needs a trailing comma, such as (7,). Parentheses alone simply group an expression; (7) is an integer. See two practical examples, edge cases and common mistakes.

2 views Published Oct 17, 2026 Updated Oct 18, 2026 Admin

A function expects a sequence even when only one measurement is available.

What You Need to Understand


A single-element tuple needs a trailing comma, such as (7,). Parentheses alone simply group an expression; (7) is an integer.

When to Use It


A function expects a sequence even when only one measurement is available.

Step-by-Step Python Example


single_score = (88,)
not_a_tuple = (88)
print(type(single_score).__name__)
print(type(not_a_tuple).__name__)
print(len(single_score))

How the Example Works


The comma makes the first expression a tuple containing one integer; the second remains an integer.

Example Output


tuple
int
1
red

A Second Example


Compare this smaller variation with the main example, then experiment with your own values.

colors = ("red",)
print(colors[0])

Important Behavior and Edge Cases


Forgetting the comma is a frequent source of bugs in APIs that expect tuples. An empty tuple uses () with no comma.

Try It Yourself


Make a one-item tuple containing a product name and confirm its length.

Common Beginner Mistakes


  • Forgetting the comma is a frequent source of bugs in APIs that expect tuples. An empty tuple uses () with no comma.
  • Assuming every sequence operation modifies the original data or that a tuple makes nested mutable objects immutable.

Key Takeaways


  • A single-element tuple needs a trailing comma, such as (7,).
  • The comma makes the first expression a tuple containing one integer; the second remains an integer.
  • Forgetting the comma is a frequent source of bugs in APIs that expect tuples.
Share this resourceSend this page to someone who may find it useful.