Advertisement
# Python < operator example
if 5 < 10: #comparing an integer to another integer
print("5 is less than 10")
if 'a' < 'b': #comparing a string with another string(in Python even a single character is termed as a string)
print("a is less than b")
if 100.5 < 100.4 : #comparing a floating value with another floating value
print("100.5 is less than 100.4")
if 100 < 100.001 : #comparing an integer with a floating value
print("100 is less than 100.001")
5 is less than 10
a is less than b
100 is less than 100.001
# Python > operator example
if 10 > 10 : #comparing an integer with an integer
print("10 is greater than 10")
if 'b' > 'a' : #comparing a string with a string(in Python even a single character is treated as a string)
print("b is greater than a")
if 100.5 > 100.4999 : #comparing a floating value with another floating value
print("100.5 is greater than 100.4999")
if 100 > 100.001 : #comparing an int with a floating value
print("100 is greater than 100.001")
b is greater than a
100.5 is greater than 100.4999
Advertisement
# Python <= operator example
if 'a' <= 'b' : #comparing a string with another string(in Python even a single character is termed as a string)
print("a is less than or equal to b")
if 'z' <= 'z' : #comparing a string with another string(in Python even a single character is termed as a string)
print("z is less than equal to z")
if 30.5 <= 31 : #comparing an floating value value with integer
print("30.5 is less than or equal to 31")
if 20.5 <= 20.6 : #comparing an floating value value with integer
print("20.5 is less than or equal to 20.6")
if 10.5 <= 10.5 : #comparong a floating value with a floating value
print("10.5 is less than or equal to 10.5")
if 5 <= 5 : #comparing an integer to an integer
print("5 is less than or equal to 5")
if 6 <= 6.0 : #comparing an integer with a floating value
print("6 is less than or equal to 5")
if 10 <= 6 : #comparing an integer with a floating value
print("10 is less than or equal to 6")
a is less than or equal to b
z is less than equal to z
30.5 is less than or equal to 31
20.5 is less than or equal to 20.6
10.5 is greater or equal to 10.5
5 is less than or equal to 5
6 is less than or equal to 5
Note: There should never be any space between < and = of <= operator, or a compile error is thrown.
# Python >= operator example
if 'z' >= 'b' : #comparing a string with another string(in Python even a single character is termed as a string)
print("z is greater than or equal to b")
if 'z' >= 'z' : #comparing a string with another string(in Python even a single character is termed as a string)
print("z is greater than equal to z")
if 50.5 >=50 : #comparing an floating value with integer
print("50.5 is greater than or equal to 50")
if 19.7 >=21.7 : #comparing a floating value with a floating value
print("19.7 is greater than or equal to 21.7")
if 10.5 >= 10.5 : #comparing a floating value with a floating value
print("10.5 is greater or equal to 10.5")
if 5 >= 5.0 : #comparing an integer to integer
print("5 is greater than or equal to 5.0")
if 6 >= 10 : #comparing a integer with a floating value
print("6 is greater than or equal to 10")
z is greater than or equal to b
z is greater than equal to z
50.5 is less than or equal to 50
10.5 is greater or equal to 10.5
5 is greater than or equal to 5.0
Note: There should never be any space between > and = of >= operator, or a compile error is thrown.
# Python == operator example
if 'z' == 'z' : #comparing a character to another character
print("z is equal to z")
if 50.5 == 50.5 : #comparing an floating value to another floating value
print("50.5 is equal to 50.5")
if 100 == 100.001 : #comparing an integer with a floating value
print("100 is equal to 100.001")
if 99.9999 == 99.999 : #comparing a floating value with a floating value
print("99.9999 is equal to 99.999")
if 5 == 5.0 : #comparing an integer to floating value
print("5 is equal to 5.0")
if 10 == 10 : #comparing an integer to integer
print("10 is equal to 10")
if 97 == "ab" : # A string in python can be compared to another value only using == operator.
print("97 is equal to a")
z is equal to z
50.5 is equal to 50.5
5 is equal to 5.0
10 is equal to 10
Note: There should never be any space between = and = of == operator, or a compile error is thrown.
# Python != operator example
if 'z' != 'a' : #comparing a character to another character
print("z is not equal to a")
if 100 != 100.001 : #comparing an integer with a floating value
print("100 is not equal to 100.001")
if 99.9999 != 99.999 : #comparing a floating value with a floating value
print("99.9999 is not equal to 99.999")
if 5.00 != 5.0 : #comparing an integer to floating value
print("5.00 is not equal to 5.0")
if 11 !=10 : #comparing an integer to an integer
print("11 is not equal to 10")
if 98 != 'hello' : # A string in python can be compared to another value only using == operator.
print("98 is not equal to a")
z is not equal to a
100 is not equal to 100.001
99.9999 is not equal to 99.999
11 is not equal to 10
98 is not equal to a
Note : There should never be any space between ! and = of != operator, or a compile error is thrown.
Advertisement
Advertisement
Please check our latest addition
PYTHON
Advertisement