Chaining Comparison Operators in Python

Consider a following piece of code in python programming language:


age = 22

if age>=18 and age<60:
    print('You are Eligible')
else:
    print('You are not Eligible')

In above program we are using two different condition in if statement, first age>=18 and age<60. Result of these two conditions are then operated using logical operators and. In python, we can chain comparison operators, so, instead of comparing multiple condition, we can combine them in one like we write in mathematics i.e. 18 <= age <60. This is known as Chaining Comparison Operators.

So, above program is identical to:


age = 22

if 18 <= age < 60:
    print('You are Eligible')
else:
    print('You are not Eligible')