Precedence of Mathematical Operations in Python
Python's mathematical operations have the same precedence as in regular mathematics. That is, multiplication and division are performed first, and then addition and subtraction. In the following example, 2 is first multiplied by 2, and then 3 is added to the result:
res = 2 * 2 + 3 # 7 (result 4 + 3)
print(res)
The following code is given:
res = 2 + 3 * 4
print(res)
Tell me what will be output to the console.
The following code is given:
res = 10 - 6 / 3
print(res)
Tell me what will be output to the console.
The following code is given:
res = 10 - 6 * 3 - 5
print(res)
Tell me what will be output to the console.