Search⌘ K
AI Features

Different Operators in Conditions

Explore how to use different relational operators such as <, >, ==, and logical operators like and, or, and not to build effective conditions in Python. Understand the difference between unary and binary operators and how Python evaluates expressions to guide decision control in programming.

Nuances of conditions

A condition is built using relation operators <, >, <=, >=, ==, and !=.

10 < 20 # yields True
'Santosh' < 'Adi' # yields False, alphabetical order is checked
'gang' < 'Good' # yields False, lowercase is > uppercase
Build conditions using relation operators

Note: In Python, a = b is assignment, and a == b is comparison.

Ranges or multiple equalities can be checked more naturally, as shown below:

if a < b < c : # checks whether b falls between a and c
if a == b == c : # checks whether all three are equal
if 10 != 20 != 10 : # evaluates to True, even though 10 != 10 is False
Ranges or multiple equalities

Any nonzero number (positive, negative, integer, float) is treated as True, and 0 is treated as ...