Explanation:
๐ข Step 1: Understand the Expression
print(True + 2 * False + 3)
Python treats Boolean values as integers in arithmetic:
True → 1
False → 0
So the expression becomes:
print(1 + 2 * 0 + 3)
๐ก Step 2: Evaluate Multiplication First
According to operator precedence, * is evaluated before +.
2 * 0 = 0
Now the expression becomes:
print(1 + 0 + 3)
๐ต Step 3: Evaluate Addition
From left to right:
1 + 0 = 1
Then:
1 + 3 = 4
So we get:
print(4)
๐ฏ Final Output
4

0 Comments:
Post a Comment