2

In the book Learning Python, there are two kinds of assignments:

list assignment:

[a,b] = [1,2]

tuple assignment:

a,b = [1,2]

I don't see any difference in result of this two kinds of assignments, is there any difference I don't know yet?

If there isn't, why are they called different names?

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
CarmeloS
  • 7,868
  • 8
  • 56
  • 103
  • **Not** a dupe! Accepted answer in the suggested duplicate avoids answering this part of the (dup) question. (It simply shows that sometimes parens are required for the tuple assignment to work.) – jpaugh Jan 05 '18 at 23:55

1 Answers1

1

They do the same thing. A tuple is a read-only version of a list. Usually you use parentheses (a, b) to create tuples versus square brackets [a, b] for lists, but the parentheses can sometimes be omitted. You could also write:

(a,b) = [1,2]

Or, perhaps most common:

a,b = 1,2
John Kugelman
  • 349,597
  • 67
  • 533
  • 578