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.
We'll cover the following...
We'll cover the following...
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 = bis assignment, anda == bis comparison.
Ranges or multiple equalities can be checked more naturally, as shown below:
if a < b < c : # checks whether b falls between a and cif a == b == c : # checks whether all three are equalif 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 ...