Explanation:
1. Assign x
x = True
Here, the variable x is assigned the Boolean value True.
In Python, Boolean values can also behave like integers:
True = 1
False = 0
So:
x = 1
2. Assign y
y = False
The variable y is assigned the Boolean value False.
In numeric operations:
False = 0
So:
y = 0
3. Perform the Addition
print(x + y + True)
Python treats the Boolean values as integers during addition.
So the expression becomes:
1 + 0 + 1
4. Calculate the Result
Now Python performs the addition:
1 + 0 = 1
Then:
1 + 1 = 2
Therefore:
x + y + True = 2
5. print() Displays the Result
The print() function displays:
print(2)
✅ Final Output
2

0 Comments:
Post a Comment