Answer the question
In order to leave comments, you need to log in
What is the order of evaluation in Python?
Hello!
There is such an expression:
10 - 2 + 3 - 6 =?
They write that the order of calculations in Python is as follows:
1. Expression in brackets;
2. Exhibitors;
3. Multiplication;
4. Division;
5. Addition;
6. Subtraction.
Those. addition comes first, and then subtraction. So, the answer to the expression at the beginning of the text position is "-1".
However, Python returns "5".
How so? O.o
Python just calculates in order from left to right?
Tried in Jupiter Notebook and Wing101
Answer the question
In order to leave comments, you need to log in
Those. addition comes first, and then subtraction. So, the answer to the expression at the beginning of the text position is "-1".
Because subtraction is addition to a negative number, permuting the terms does not change the value.
The interpreter reads your expression as 10 + 3 - 2 - 6.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question