Relational Operator in Python

Relational Operator in Python



Symbol
Description
Example 1
Example 2
<
Less than

>>>7<10

True

>>> 7<5

False

>>> 7<10<15

True

>>>7<10 and 10<15

True

>>>"Hello"< "Goodbye"

False

>>>'Goodbye'< 'Hello'

True

>Greater than

>>>7>5

True

>>>10<10

False

>>>„Hello‟> „Goodbye‟

True

>>>'Goodbye'> 'Hello'

False

<=
less than equal to

>>> 2<=5

True

>>> 7<=4

False

>>>"Hello"<= "Goodbye"

False

>>>'Goodbye' <= 'Hello'

True

>=greater than equal to

>>>10>=10

True

>>>10>=12

False

>>>"Hello">= "Goodbye"

True

>>>'Goodbye' >= 'Hello'

False

! =, <>
not equal to

>>>10!=11

True

>>>10!=10

False

>>>‟Hello‟!= "HELLO"

True

>>> "Hello‟ != "Hello‟

False

==
equal to

>>>10==10

True

>>>10==11

False

>>>"Hello" == "Hello"

True

>>>"Hello" == "Good Bye"

False

Example: To test Relational Operators:


#Demo Program to test Relational Operators
a=int (input("Enter a Value for A:"))
b=int (input("Enter a Value for B:"))
print ("A = ",a," and B = ",b)
print ("The a==b = ",a==b)
print ("The a > b = ",a>b)
print ("The a < b = ",a<b)
print ("The a >= b = ",a>=b)
print ("The a <= b = ",a<=0)
print ("The a != b = ",a!=b)
#Program End


Output:


Enter a Value for A:35

Enter a Value for B:56

A = 35 and B = 56

The a==b = False

The a > b = False

The a < b = True

The a >= b = False

The a <= b = False

The a != b = True

Python : Relational Operator in Python Program List