In an assignment statement, the right-hand side is always evaluated fully before doing the actual setting of variables. So,
x, y = y, x + y
evaluates y
(let’s call the result ham
), evaluates x + y
(call that spam
), then sets x
to ham
and y
to spam
. I.e., it’s like
ham = y
spam = x + y
x = ham
y = spam
By contrast,
x = y
y = x + y
sets x
to y
, then sets y
to x
(which == y
) plus y
, so it’s equivalent to
x = y
y = y + y
Related Contents:
- Is it possible only to declare a variable without assigning any value in Python?
- Set variable in jinja
- What is the difference between shallow copy, deepcopy and normal assignment operation?
- Assignment inside lambda expression in Python
- Why isn’t assigning to an empty list (e.g. [] = “”) an error?
- Is it possible to overload Python assignment?
- Why does foo = filter(…) return a , not a list? [duplicate]
- Assign variable in while loop condition in Python?
- Difference between a -= b and a = a – b in Python
- How to make a copy of a 2D array in Python? [duplicate]
- How to assign a value to a TensorFlow variable?
- Python: Assign Value if None Exists
- assigning class variable as default value to class method argument
- Why can I use the same name for iterator and sequence in a Python for loop?
- Local variable referenced before assignment? [duplicate]
- Multiple assignment semantics
- Unexpected behaviour with a conditional generator expression [duplicate]
- Assignment with “or” in python [closed]
- What is this kind of assignment in Python called? a = b = True
- Python Multiple Assignment Statements In One Line
- Python initialize multiple variables to the same initial value
- How to assign a variable in an IF condition, and then return it?
- Substitute multiple whitespace with single whitespace in Python [duplicate]
- Recommendations of Python REST (web services) framework? [closed]
- Is Python strongly typed?
- How do you write tests for the argparse portion of a python module?
- How to do multiple arguments to map function where one remains the same
- How could I use requests in asyncio?
- virtualenv –no-site-packages and pip still finding global packages?
- Difference between coroutine and future/task in Python 3.5?
- Specify format of floats for tick labels
- drop into python interpreter while executing function
- Lambda including if…elif…else
- Error message “Linter pylint is not installed”
- Virtualenv and source version control
- Does the Python 3 interpreter have a JIT feature?
- Checking if a website is up via Python
- Is there a list of line styles in matplotlib?
- How to make Python speak
- pip requirements.txt with alternative index
- How to completely traverse a complex dictionary of unknown depth?
- how to find the target file’s full(absolute path) of the symbolic link or soft link in python
- ValueError: Grouper for not 1-dimensional
- How can I sandbox Python in pure Python?
- Where should utility functions live in Django?
- How to limit the size of a dictionary?
- How to preview a part of a large pandas DataFrame, in iPython notebook?
- How can I check if a Pandas dataframe’s index is sorted
- Difference between plt.draw() and plt.show() in matplotlib
- My rst README is not formatted on pypi.python.org