+ 3

Basic Python Question

Guys why that code series turn 4 at terminal? Because one of them is integer and the other one is boolean. So it has to give error because we can't do process with different data types. I am really confused. x= 3 y= True print(x+y)

14th Jan 2022, 12:30 PM
Ork
2 Answers
+ 8
Pariket Thakur , sorry to say, but your answer is not complete correct. True == 1 False == 0 # <<< so the addition of x (3) + y (True) is the same as: 3 + 1
14th Jan 2022, 12:43 PM
Lothar
Lothar - avatar
+ 3
Lothar Oops ! I am extremely sorry for this actually I was trying to type fast True == 1 False == 0
14th Jan 2022, 1:35 PM
Pariket Thakur
Pariket Thakur - avatar