Explanation:
Step 1: Evaluate 10 // 3
// is the floor division operator.
It divides the numbers and returns the whole number (integer) part, ignoring the decimal.
Calculation:
10 // 3
Normal division:
10 / 3 = 3.333333...
Floor division removes the decimal part:
10 // 3 = 3
Current expression becomes:
print(3 * 3)
Step 2: Evaluate 3 * 3
* is the multiplication operator.
Calculation:
3 * 3 = 9
Current expression becomes:
print(9)
Step 3: Execute print()
The print() function displays the result on the screen.
print(9)
Output:
9
Operator Precedence
Both // (floor division) and * (multiplication) have the same precedence in Python.
When operators have the same precedence, Python evaluates them from left to right.
Expression:
10 // 3 * 3
Evaluation order:
10 // 3 → 3
3 * 3 → 9
Final Output
9

0 Comments:
Post a Comment