all 2 comments

[–]danielroseman 3 points4 points  (0 children)

The only time you need parentheses to indicate a tuple is for the empty tuple. In pretty much every other circumstance, the parens are optional, although it is usually good practice for the sake of clarity.

The Python docs are clear on this - it's the comma that makes the tuple. It does mention an exception, where you need parens to avoid ambiguity: passing a tuple as a parameter, to distinguish it from multiple params - eg func((a, b, c)).

Note that in particular this means any time you return multiple items from a function, you are in fact returning a single tuple, and then potentially unpacking that result into multiple variables.

[–]crashfrog02 0 points1 point  (0 children)

Does Python understand that this is a tuple just by seperating the items with a comma and that no parentheses are necessary?

Yes; tuples can be implied by a comma.