r/ProgrammerTIL • u/cdrini • Sep 12 '17
Python [Python] TIL that you can chain comparisons
For example:
x = 3
0 < x < 10 # -> TrueWikipedia: https://en.wikipedia.org/wiki/Python_syntax_and_semantics#Comparison_operators
Python Docs: https://docs.python.org/3/reference/expressions.html#comparisons
Edit: formatting
69
Upvotes
View all comments
Show parent comment
1
u/j-frost Sep 27 '17
JavaScript (as usual) actually doesn't behave very well. For instance,
because
-1 < 0 === trueand sincetrue == 1,true < 1 === false.