Recall & Review
beginner
What is a single-element tuple in Python?
A single-element tuple is a tuple that contains exactly one item. It must have a comma after the item to be recognized as a tuple.
Click to reveal answer
beginner
Why do we need a comma after the single element in a tuple?
The comma tells Python that this is a tuple. Without the comma, Python treats the parentheses as just grouping, not a tuple.
Click to reveal answer
beginner
Which of these is a single-element tuple?
(5) or (5,)?(5,) is a single-element tuple. (5) is just the number 5 inside parentheses.Click to reveal answer
beginner
How do you create a single-element tuple with the string 'hello'?
You write
('hello',) with a comma after the string inside parentheses.Click to reveal answer
beginner
What happens if you forget the comma in a single-element tuple?
Python will not create a tuple. Instead, it will treat the value as the type of the single element itself.
Click to reveal answer
Which of the following is a valid single-element tuple?
✗ Incorrect
Only (42,) is a single-element tuple. (42) is just 42 in parentheses, [42] is a list, and {42} is a set.
What does Python interpret (7) as?
✗ Incorrect
(7) is just the number 7 inside parentheses, so Python treats it as the number 7.
How do you create a single-element tuple with the boolean value True?
✗ Incorrect
You need the comma to make it a tuple: (True,). Without the comma, it's just True in parentheses.
What is the type of ("apple",)?
✗ Incorrect
("apple",) is a tuple containing one string element.
Why is the comma important in single-element tuples?
✗ Incorrect
The comma tells Python this is a tuple, not just a grouped value.
Explain how to create a single-element tuple and why the comma is necessary.
Think about how Python reads parentheses and commas.
You got /3 concepts.
What happens if you write (5) instead of (5,)? How does Python interpret each?
Consider the difference between grouping and tuple creation.
You got /3 concepts.