Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

I am new to python, and not able to understand the below code:

>>> 0 < 10 != 1 < 5

True

When 0<10 is true and 1<5 is also true. True != True should be false right. Then why is the output True ???

1 Answer

0 votes
by (36.8k points)
edited by

Because of the operation's priorities, the meaning of the expression is different. You need to put the parentheses: (0 < 10) != (1 < 5), to get the desired output.

Otherwise, your first expression means the same as (0 < 10) and (10 != 1) and (1 < 5) which is not the output you wanted. 

If you are a beginner and want to know more about Python the do check out the Data Science with Python Course

Browse Categories

...