How does Python's comma operator works during assignment?

后端 未结 3 1210
栀梦
栀梦 2020-11-29 05:58

I was reading the assignment statements in the Python docs ( http://docs.python.org/reference/simple_stmts.html#assignment-statements ).

In that it is quoted that:

3条回答
  •  [愿得一人]
    2020-11-29 06:24

    You can think of the assignments happening in parallel on copies rather than sequentially and in-place.

    This is why in python you dont need a swap function:

    a, b = b, a
    

    works sufficiently without requiring a temp variable, c.

提交回复
热议问题