Explanation:
1. Assign Value to a
a = 0
a stores 0.
0 is Falsy in Python.
2. Assign Value to b
b = 7
b stores 7.
7 is Truthy.
3. Assign Value to c
c = 3
c stores 3.
3 is Truthy.
4. Evaluate the Expression
print(a or b and c)
Python evaluates and before or.
So the expression becomes:
print(a or (b and c))
5. Evaluate b and c
7 and 3
Both values are truthy, so and returns the last value:
3
6. Evaluate a or 3
0 or 3
Since 0 is falsy, or returns the other value:
3
7. Final Output
3
8. Important Rule
and → higher precedence
or → lower precedence
Therefore:
a or b and c
is evaluated as:
a or (b and c)
Answer: 3

0 Comments:
Post a Comment