Chained Comparison
Using this code snippet, we can make multiple comparisons with all kinds of comparison operators in just a single line.
Python: 3.0    Anurag Rana    29 Jan 2022   0
Login to upvote
1
2
3
4
5
6
a = 5

print(2 < a < 8)
# True
print(1 == a < 3)
# False
Copy | Download as: .py file   PNG
Share on: FB   Twitter   LinkedIn   WA
©2021 - code108labs   Contributors   Hosted on DigitalOcean   Partner website: pythoncircle.com