I have this code:
if self.date: # check date is not NoneType
if self.live and self.date <= now and self.date >= now:
return True
return False
My IDE says: This looks like it should be simplified i.e. Python chained comparison.
What is a chained comparison and how can it be simplified?
An example of a chained comparison is shown below.
age = 25
if 18 < age <= 25:
print('Chained comparison!')
Note that beneath the covers this is exactly the same as shown below, it just looks nicer.
age = 25
if 18 < age and age <= 25:
print('Chained comparison!')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With