4 ms·
What does he mean by "# Tuples are created by default if you leave out the parentheses". With or without the parens I'm getting the same result for "a, b, c =
by xutopia 13y ago
What does he mean by "# Tuples are created by default if you leave out the parentheses".
With or without the parens I'm getting the same result for "a, b, c = (1, 2, 3)"
- eurleif 13y agoYes, that is the same with or without parentheses. You're creating a tuple on the right-hand side of the equal sign, and using tuple unpacking on the left-hand side to assign the members of that tuple to variables. To make it a bit more clear, you can add parentheses on the left to match the ones on the right: (a, b, c) = (1, 2, 3)
- madelfio 13y agoYou get a list if you do "object_a = [1, 2, 3]" and a tuple if you do "object_b = (1, 2, 3)". Then try "object_c = 1, 2, 3" and you'll also get the tuple.
- cben 13y agoYou should also mention the 1-item case where the (optional in other cases) trailing comma is required to form a tuple: (1,)