Back
+10 XP
Concept

Single-Item Tuples: The Comma Rule

Parentheses around a single value mean math grouping. To create a 1-item tuple, you MUST include a trailing comma `(item,)`.

python
x = (42)    # Just the integer 42!
y = (42,)   # A real 1-item tuple!
print(type(x))  # <class 'int'>
print(type(y))  # <class 'tuple'>

# 75. Single-Item Tuples: The Comma Rule Parentheses around a single value mean math grouping. To create a 1-item tuple, you MUST include a trailing comma `(item,)`: ```python x = (42) # Just the integer 42! y = (42,) # A real 1-item tuple! print(type(x)) # <class 'int'> print(type(y)) # <class 'tuple'> ``` Without the comma, Python treats `(42)` as simple arithmetic parentheses and hands you an integer. The trailing comma tells Python: "This is a tuple container."

Checkpoint

How do you create a tuple containing only the number `5`?

Practice

Create a 1-item tuple containing the string `"solo"` and print its type with `type()`.

Terminal
01
Tap code blocks below to assemble
Available Blocks