What is the output of the following Python code? t = (5); u = (5,); print(type(t).__name__, type(u).__name__)
Correct answer C. int tuple
Explanation
Parentheses alone only group an expression, so (5) is simply the integer 5. It is the comma that makes a tuple, so a one-item tuple needs a trailing comma, as in (5,) or even 5,. This is why the tutorial calls single-item tuple syntax ugly but necessary.
Answer checked How we write and check questions
Discussion