Python: Assignment Operators

Python: Assignment Operators

>>> x = 7
>>> y = x
>>> print(y)
7

Assign multiple variables at once:

x, y, z = 7, 8, 9

Can use this when assigning closely related variables, like the width and height or an object coordinates

Can use plus equals operator or something like this:

x += 2  # equals to: x = x + 2
x -= 2  # equals to: x = x - 2
x *= 2  # equals to: x = x * 2
...

猜你喜欢

转载自blog.csdn.net/guo_ya_nan/article/details/80259617