Explanation:
1. First Value: ""
""
An empty string is falsy in Python.
So Python does not select it and moves to the next value:
"" → False
2. Second Value: []
[]
An empty list is also falsy.
Therefore, Python continues to the next value:
[] → False
3. Third Value: 5
5
Any non-zero number is truthy.
So Python selects 5 and stops evaluating the or chain.
5 → True
4. Assignment to x
The complete expression:
x = "" or [] or 5
becomes:
x = 5
Important: Python's or operator returns the actual value, not necessarily True or False.
5. print(x)
print(x)
Since x contains 5, the output is:
5
✅ Final Output
5

0 Comments:
Post a Comment