PYTHON RELATIONAL OPERATOR
GREATER THAN OPERATOR (>):
GREATER THAN operator compare two numbers and return TRUE if the first number is greater than the second number. Otherwise it will return FALSE.
So the result is always a Boolean value.
INTEGER:
# RELATIONAL OPERATOR example 1
a = 9
b = 2
c = a > b
print("\nValue of a -> ", a)
print("\nValue of b -> ", b)
print("\nValue of a > b -> ", c)
print("\nData Type of a > b -> ", type(c))
PYTHON RELATIONAL OPERATORS : Output
Value of a -> 9
Value of b -> 2
Value of a > b -> True
Data Type of a > b -> <class 'bool'>
# RELATIONAL OPERATOR example 2
a = 9
b = 2
c = a > b
print("\nValue of a -> ", a)
print("\nValue of b -> ", b)
print("\nValue of b > a -> ", c)
print("\nData Type of a > b -> ", type(c))
PYTHON RELATIONAL OPERATORS : Output
Value of a -> 9
Value of b -> 2
Value of b > a -> True
Data Type of b > a -> <class 'bool'>
FLOATING:
# RELATIONAL OPERATOR example 1
a = 9.5
b = 2.4
c = a > b
print("\nValue of a -> ", a)
print("\nValue of b -> ", b)
print("\nValue of a > b -> ", c)
print("\nData Type of a > b -> ", type(c))
PYTHON RELATIONAL OPERATORS : Output
Value of a -> 9.5
Value of b -> 2.4
Value of a > b -> True
Data Type of a > b -> <class 'bool'>
# RELATIONAL OPERATOR example 2
a = 9.5
b = 2.4
c = b > a
print("\nValue of a -> ", a)
print("\nValue of b -> ", b)
print("\nValue of b > a -> ", c)
print("\nData Type of b > a -> ", type(c))
PYTHON RELATIONAL OPERATORS : Output
Value of a -> 9.5
Value of b -> 2.4
Value of b > a -> False
Data Type of b > a -> <class 'bool'>
GREATER THAN OR EQUAL TO OPERATOR (>=):
GREATER THAN OR EQUAL TO operator compare two numbers and return TRUE if the first number is greater than or equal to the second number. Otherwise it will return FALSE. So the result is always a Boolean value.
INTEGER:
# GREATER THAN OR EQUAL TO OPERATOR example
a = 9
b = 2
c = a > b
print("\nValue of a -> ", a)
print("\nValue of b -> ", b)
print("\nValue of a > b -> ", c)
a = 2
b = 2
c = a >= b
print("\nValue of a -> ", a)
print("\nValue of b -> ", b)
print("\nValue of a >= b -> ", c)
PYTHON RELATIONAL OPERATORS : Output
Value of a -> 9
Value of b -> 2
Value of a > b -> True
Value of a -> 2
Value of b -> 2
Value of a >= b -> True
FLOATING:
# GREATER THAN OR EQUAL TO OPERATOR example
a = 9.5
b = 2.4
c = a > b
print("\nValue of a -> ", a)
print("\nValue of b -> ", b)
print("\nValue of a > b -> ", c)
a = 2.4
b = 2.4
c = a >= b
print("\nValue of a -> ", a)
print("\nValue of b -> ", b)
print("\nValue of a >= b -> ", c)
PYTHON RELATIONAL OPERATORS : Output
Value of a -> 9.5
Value of b -> 2.4
Value of a > b -> True
Value of a -> 2.4
Value of b -> 2.4
Value of a >= b -> True
LESS THAN OPERATOR (<):
LESS THAN operator compare two numbers and return TRUE if the first number is lower than the second number. Otherwise it will return FALSE.
INTEGER:
# LESS THAN OPERATOR example
a = 2
b = 9
c = a < b
print("\nValue of a -> ", a)
print("\nValue of b -> ", b)
print("\nValue of a < b -> ", c)
c = b < a
print("\nValue of b < a -> ", c)
PYTHON RELATIONAL OPERATORS : Output
Value of a -> 2
Value of b -> 9
Value of a < b -> True
Value of b < a -> False
FLOATING:
# LESS THAN OPERATOR example
a = 2.4
b = 9.5
c = a < b
print("\nValue of a -> ", a)
print("\nValue of b -> ", b)
print("\nValue of a < b -> ", c)
c = b < a
print("\nValue of b < a -> ", c)
PYTHON RELATIONAL OPERATORS : Output
Value of a -> 2.4
Value of b -> 9.5
Value of a < b -> True
Value of b < a -> False
LESS THAN OR EQUAL TO OPERATOR (<=):
LESS THAN OR EQUAL TO operator compare two numbers and return TRUE if the first number is less than or equal to the second number. Otherwise it will return FALSE.
INTEGER:
# LESS THAN OR EQUAL TO OPERATOR example
a = 2
b = 9
c = a <= b
print("\nValue of a -> ", a)
print("\nValue of b -> ", b)
print("\nValue of a <= b -> ", c)
c = b <= a
print("\nValue of b < a -> ", c)
PYTHON RELATIONAL OPERATORS : Output
Value of a -> 2
Value of b -> 9
Value of a <= b -> True
Value of b < a -> False
FLOATING:
# LESS THAN OR EQUAL TO OPERATOR example
a = 2.4
b = 9.5
c = a <= b
print("\nValue of a -> ", a)
print("\nValue of b -> ", b)
print("\nValue of a <= b -> ", c)
c = b <= a
print("\nValue of b < a -> ", c)
PYTHON RELATIONAL OPERATORS : Output
Value of a -> 2.4
Value of b -> 9.5
Value of a <= b -> True
Value of b < a -> False
EQUAL TO OPERATOR (==):
EQUAL TO operator compare two numbers and return TRUE if the first number is equal to the second number. Otherwise it will return FALSE.
INTEGER:
# EQUAL TO OPERATOR example
a = 2
b = 2
c = a == b
print("\nValue of a -> ", a)
print("\nValue of b -> ", b)
print("\nValue of a == b -> ", c)
a = 9
b = 2
c = a == b
print("\nValue of a -> ", a)
print("\nValue of b -> ", b)
print("\nValue of a == b -> ", c)
PYTHON RELATIONAL OPERATORS : Output
Value of a -> 2
Value of b -> 2
Value of a == b -> True
Value of a -> 9
Value of b -> 2
Value of a == b -> False
FLOATING:
# EQUAL TO OPERATOR example
a = 2.5
b = 2.5
c = a == b
print("\nValue of a -> ", a)
print("\nValue of b -> ", b)
print("\nValue of a == b -> ", c)
a = 9.5
b = 2.5
c = a == b
print("\nValue of a -> ", a)
print("\nValue of b -> ", b)
print("\nValue of a == b -> ", c)
PYTHON RELATIONAL OPERATORS : Output
Value of a -> 2.5
Value of b -> 2.5
Value of a == b -> True
Value of a -> 9.5
Value of b -> 2.5
Value of a == b -> False
NOT EQUAL TO OPERATOR (!=):
NOT EQUAL TO operator compare two numbers and return TRUE if the first number is not equal to the second number. Otherwise it will return FALSE.
INTEGER:
# NOT EQUAL TO OPERATOR example
a = 9
b = 2
c = a != b
print("\nValue of a -> ", a)
print("\nValue of b -> ", b)
print("\nValue of a != b -> ", c)
a = 2
b = 2
c = a != b
print("\nValue of a -> ", a)
print("\nValue of b -> ", b)
print("\nValue of a != b -> ", c)
PYTHON RELATIONAL OPERATORS : Output
Value of a -> 9
Value of b -> 2
Value of a != b -> True
Value of a -> 2
Value of b -> 2
Value of a != b -> False
FLOATING:
# NOT EQUAL TO OPERATOR example
a = 9.5
b = 2.5
c = a != b
print("\nValue of a -> ", a)
print("\nValue of b -> ", b)
print("\nValue of a != b -> ", c)
a = 2.5
b = 2.5
c = a != b
print("\nValue of a -> ", a)
print("\nValue of b -> ", b)
print("\nValue of a != b -> ", c)
PYTHON RELATIONAL OPERATORS : Output
RELATED TOPICS:
Pingback: PYTHON ARITHMETIC OPERATORS - Sayantan's Blog On Python Programming
Pingback: PYTHON LOGICAL OPERATORS - Sayantan's Blog On Python Programming
Pingback: PYTHON IDENTIFY OPERATORS - Sayantan's Blog On Python Programming