Why does Python treat a tuple with one item as an integer?

Viewed 733

See the following example:

(1) #outputs 1

But if I add the comma, it will be right according to the Python docs:)

(1,) #output (1,)

That's super odd to me. Can anyone explain this?

A related question: Is there not a way for Python to know when (1) should be a tuple (1,) instead of 1?

Thanks for future replies.

1 Answers
Related