-3
a,b=['apple','banana'] 

I want to know that how the above syntax works and returns different strings 'apple' and 'banana' to a and b respectively indeed of returning a=['apple','banana'] and b=['apple','banana']

1 Answers1

0

From https://docs.python.org/3/reference/simple_stmts.html#assignment-statements

[If the target is an iterable] with the same number of items as there are targets in the target list, [...] the items are assigned, from left to right, to the corresponding targets.

[a, b] is an iterable with the same number of items as ['apple', 'banana'], so a is assigned apple and b is assigned banana.

chepner
  • 497,756
  • 71
  • 530
  • 681