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
16
u/sim642 Sep 12 '17
I now wish I could find my response to this in a past thread...
Basically, you should be very careful using this syntax because most of the expressions it allows are completely unreadable or unintuitive like
a < b > c != d >= e.19
u/bobbitfruit Sep 12 '17
Fuck.. TIL
3
u/desmonduz Sep 12 '17
does chaining mean 'and'ing them
1
u/[deleted] Sep 12 '17
That's neat.