Relational Operators in Python
==
|
Equal
to
|
x
== y
|
if
x equal to y True otherwise False
|
!=
|
Not
Equal to
|
x
!= y
|
if
x equals not b True otherwise False
|
>
|
Greater
than
|
x
> y
|
if
x Greater than y True otherwise False
|
<
|
Less
than
|
x
< y
|
True
if x less than y otherwise False
|
>=
|
Greater
than or equal to
|
x
>= y
|
if
x greater than or equal to y True otherwise
False
|
<=
|
Less
than or equal to
|
x
<= y
|
if
x less than or equal to y True otherwise False
|
Equal to(==) Relational Operator
Source Code :x = 5
y = 6
print(x == y)
print(x == y)
print((x<y) == (y>x))
Output :
False
True
True
print(x != y)
Output :
True
Not Equal to(!=) Relational Operator
Source Code :x = 5
y = 6
print(x != y)
print(x != 5)
print((x<y) != (y<x))
Output :True
False True
print(x < y)
Output :
True
Less than(<) Relational Operator
Source Code :x = 5
y = 6
print(x < y)
print(x > y)
Output :True
False
print(x > y)
Greater than(>) Relational Operator
Source Code :x = 5
y = 6
print(x > y)
print(x < y)
Output :
False
True
print(x <= y)
Less than or Equal to(<=) Relational Operator
Source Code :x = 5
y = 6
z = 5
print(x <= y)
print(y <= z)
Output :
True
True
print(x >= y)
Greater than or Equal to(>=) Relational Operator
Source Code :x = 5
y = 6
z = 5
print(x >= y)
print(x >= z)
Output :
False
True
0 Comments