Nimfa
asked

Expert
Kelish Rai answered
If you're familiar with PEMDAS, the expression 2 * 5 - 10 / 5 follows the same order of operations.
Here’s a quick breakdown of PEMDAS:
Parentheses first (none here).
Exponents next (none here).
Multiplication and Division, from left to right.
Addition and Subtraction, from left to right.
Now, let’s see how Python evaluates the expression step by step:
2 * 5 = 10, so the expression becomes10 - 10 / 5.10 / 5 = 2.0, so now we have10 - 2.0.10 - 2.0 = 8.0.
Since division in Python always produces a float, the final result is 8.0 instead of an integer.
However, if you want the result without decimals, you can use // for integer division.
result = 2 * 5 - 10 // 5
print(result) # Output: 8In this case, the result would be an integer (8), not a float (8.0).
Python
This question was asked as part of the Getting started with Python course.
Our Experts
Sudip BhandariHead of Growth/Marketing
Apekchhya ShresthaSenior Product Manager
Kelish RaiTechnical Content Writer
Abhilekh GautamSystem Engineer
Palistha SinghTechnical Content Writer
Sarthak BaralSenior Content Editor
Saujanya Poudel
Abhay Jajodia
Nisha SharmaTechnical Content Writer
Udayan ShakyaTechnical Content Writer