IKH

Relational Operators

  • > ⇒ Greater-than
  • >= ⇒ Greater-than-equals
  • < ⇒ Less-than
  • <= ⇒ Less-than-equals

Example

Python
num1 = 10
num2 = 20

print("num1 > num2 is", num1>num2)
print("num1 >= num2 is", num1>=num2)
print("num1 < num2 is", num1<num2)
print("num1<=num2 is", num1<=num2)

Output

PowerShell
num1 > num2 is False
num1 >= num2 is False
num1 < num2 is True
num1<=num2 is True
  • We can apply relational operators for str types also.

Example

Python
str1 = "ajay"
str2 = "ajay"

print("str1 > str2 is", str1>str2)
print("str1 >= str2 is", str1>=str2)
print("str1 < str2 is", str1<str2)
print("str1<=str2 is", str1<=str2)

Output

PowerShell
str1 > str2 is False
str1 >= str2 is True
str1 < str2 is False
str1<=str2 is True

Example

Python
str1 = "D"
str2 = "d"

print(str1 < str2)

Output

PowerShell
True
  • We can apply relational operators for bool types also.

Example

Python
print(True > True)
print(True >= True)
print(10 > True)
print(False > True)

Output

PowerShell
False
True
True
False
  • We can not apply relational operators for different data types.

Example

Python
print(10>"ajay")

Output

PowerShell
TypeError: '>' not supported between instances of 'int' and 'str

Remark

  • Chaining of relational operators is possible. In the chaining, if all comparisons returns True then only result is True. If at least one comparison returns False then the result is False.
Python
print(10<20)
print(10<20<30)
print(10<20<30<40)
print(10<20<3050)

Output

PowerShell
True
True
True
True

Ungraded Questions

Get ready for an exhilarating evaluation of your understanding! Brace yourself as we dive into the upcoming assessment. Your active participation is key, so make sure to attend and demonstrate your knowledge. Let’s embark on this exciting learning journey together!


Name
Email
Phone

Report an error