0

Why the output of the second print function is True although not operator is used ?

x = 5 a = print(x > 0 or x < 3) print(not a)

3rd Dec 2017, 2:11 PM
Đồng Vũ Minh Phúc
Đồng Vũ Minh Phúc - avatar
3 Respuestas
+ 6
ok, now i understood, this is happening cuz.. you put the expression in the print statement. If you had done the following: x = 5 a = x > 0 or x < 3 print(x) #True print(not x) #False then u would get the expected output
3rd Dec 2017, 2:39 PM
Cool Codin
Cool Codin - avatar
+ 1
@Cool Codin Sr mate. The third line of code or the second print function outputs True, not False. This is where I'm confusing because I used not operator, the output is supposed to be False, but it's True :)
3rd Dec 2017, 2:34 PM
Đồng Vũ Minh Phúc
Đồng Vũ Minh Phúc - avatar
0
Well...you can put Boolean expression in the print function. For example, print(5==5) or print(x>3) with x = 4, etc. The thing is print(a) and the output will be None. Subsequently, you use not operator, the output is False. I'm curious why this happens.
3rd Dec 2017, 3:29 PM
Đồng Vũ Minh Phúc
Đồng Vũ Minh Phúc - avatar