Difference between writing something on one line and on several lines

后端 未结 6 1524
我寻月下人不归
我寻月下人不归 2021-01-13 03:16

Where is the difference when I write something on one line, seperated by a , and on two lines. Apparently I do not understand the difference, because I though t

6条回答
  •  余生分开走
    2021-01-13 04:01

    This is because of Python's tuple unpacking. In the first one, Python collects the values on the right, makes them a tuple, then assigns the values of the tuple individually to the names on the left. So, if a == 1 and b == 2:

       a, b = b, a + b
    => a, b = (2, 3)
    => a = 2, b = 3
    

    But in the second example, it's normal assignment:

       a = b
    => a = 2
       b = a + b
    => b = 4
    

提交回复
热议问题