Comparison Operators

Equal
to(==)
Compares
two
variables
and
returns
the
boolean
value
True
if
they
are
equal
and
returns
False
if
they
aren't.
Variable1==Variable2
Not
equal
to
operator
(!=)
Compares
two
variables
and
returns
the
boolean
value
True
if
they
are
NOT
equal
and
returns
False
if
they
are.
Variable1!=Variable2
Greater
than
(>)
Returns
True
if
the
first
variable
is
greater
than
the
second
variable.
Variable1>Variable2
Less
than
(<)
Returns
True
if
the
first
variable
is
less
than
the
second
variable.
Variable1<Variable2
Greater
than
or
equal
to(>=)
Returns
True
if
the
first
variable
is
greater
than
or
equal
to
the
second
variable.
Variable1>=Variable2
Less
than
or
equal
to(<=)
Returns
True
if
the
first
variable
is
less
than
or
equal
to
the
second
variable.
Variable1<=Variable2
print(2==2.0)
print(3==5)
True
False
print(3!=5)
print(2!=2)
True
False
print(1>3)
print(10>8)
False
True
print(10<12)
print(10<9)
True
False
print(16>=16)
print(14>=15)
True
False
print(16<=18)
print(15<=10)
True
False

Logical Operators

and
Compares
two
statements
and
returns
True
only
if
BOTH
the
statements
are
true,
else
it
returns
False.
and
Statement1 and Statement2
or
Compares
two
statements
and
returns
True
if
any
one
of
the
statements
is
true
or
Statement1 or Statement2
Multiple
and
/
or
In
multiple
AND/OR
conditional
statements,
AND
has
precedence
over
the
OR.
Statement1 or Statement2 and Statement3
#First we solve the AND operator, and then the OR
print(3<7 and 8==8)
print(6>2 and 9==8)

print(4+5>8 or 9!=7)
print(6>7 or 8==9.0)

print(2>3 or 3==3 and 1>0)
#both 3==3 and 1>0 are TRUE, so it becomes print(2>3 or TRUE), which becomes print(FALSE or TRUE), which prints TRUE
True
False
True
False
True