Семантика множественного присваиванияPython

Программы на Python
Гость
Семантика множественного присваивания

Сообщение Гость »


В Python можно сделать:

Код: Выделить всё

a, b   = 1, 2
(a, b) = 1, 2
[a, b] = 1, 2
I checked the generated bytecode using and they are identical.

So why allow this at all? Would I ever need one of these instead of the others?

See also Multiple assignment and evaluation order in Python regarding the basic semantics of this kind of assignment.
See also Understand Python swapping: why is a, b = b, a not always equivalent to b, a = a, b? for more complex cases, where the order of assignment matters.


Источник: https://stackoverflow.com/questions/518 ... -semantics

Вернуться в «Python»