3️⃣ Relational Operators
They are also called as comparison operators.
1) Greater than (>):
Returns True if first value is greater than second, otherwise it returns False.
💻 Example:
1 2 3 4 | a = 10
b = 2
print(a > b)
print(b > a)
|
✅ Output:
True
False
2) Less than (<):
Returns True if first value is less than second, otherwise it retuns False.
💻 Example:
1 2 3 4 | a = 10
b = 2
print(a < b)
print(b < a)
|
✅ Output:
False
True
3) Equals to (==):
Returns True if first value is equal to second, otherwise it retuns False.
💻 Example:
1 2 3 4 5 | a = 10
b = 2
c = 5*2
print(a == b)
print(a == c)
|
✅ Output:
False
True
4) Not equal to (!=):
Returns True if first value is not equal to second, otherwise it retuns False.
💻 Example:
1 2 3 4 5 | a = 10
b = 2
c = 5*2
print(a != b)
print(a != c)
|
✅ Output:
True
False
4) Greater than or equal to (>=):
Returns True if first value is greater than or equal to second, otherwise it retuns False.
💻 Example:
1 2 3 4 5 6 | a = 10
b = 2
c = 5*2
print(a >= b)
print(a >= c)
print(b >= a)
|
✅ Output:
True
True
False
5) Less than or equal to (<=):
Returns True if first value is less than or equal to second, otherwise it retuns False.
💻 Example:
1 2 3 4 5 6 | a = 10
b = 2
c = 5*2
print(a <= b)
print(a <= c)
print(b <= a)
|
✅ Output:
False
True
True
Be prepared with below questions prior to your interview !
Frequently asked Interview Questions
What are relational operators in Python?
How does the equality operator (==) work in Python?
What is difference between (=) and (==) operators?