Python is one of the most popular programming languages these days, as it can be used in many areas.
Part of the reason why it is so popular is the fact that it has a lot of helpful libraries that can be used.
I have been using it for quite some time now but didn’t know that you could do one type of comparison which is very intuitive and is widely used in Math.
If you have a value and you want to compare it whether it is between two other values, there is a simple expression that you use in Math:
1 < x < 10
That is the algebraic expression that we learn since elementary school. However, you can also use that same expression in Python as well.
Yes, you heard that right. You have probably done comparisons of such form:
1 < x and x < 10
For that, you simply need to use:
1 < x < 10
This doesn’t work in Ruby, the programming language that was developed with the intention of making programmers happy. This turns out to be working in JavaScript as well.
I was really impressed seeing such a simple expression not being talked about more widely. At least, I haven’t seen it being mentioned that much.
I hope you find it useful.