Practice mode Python

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.