Python Comparison Operators | Non-Programmers | Tech Arkit


## Equality (==): Checks if two values are equal. 
## Strings are case sensitive Ravi == Ravi (True) however Ravi == ravi (False).
x = 5
y = 7
print(x == y)  # False

name1 = "Ravi"
name2 = "Ravi"
print(name1 == name2)  # True

## Inequality (!=): Checks if two values are not equal.
a = 10
b = 15
print(a != b)  # True

age1 = 25
age2 = 30
print(age1 != age2)  # True

## Greater than (>): Checks if the left operand is greater than the right operand.
m = 5
n = 3
print(m > n)  # True

score1 = 85
score2 = 90
print(score1 > score2)  # False


## Less than (<): Checks if the left operand is less than the right operand.
p = 7
q = 10
print(p < q)  # True

temperature1 = 25
temperature2 = 30
print(temperature1 < temperature2)  # True


## Greater than or equal to (>=): Checks if the left operand is greater than or equal to the right operand.
c = 5
d = 5
print(c >= d)  # True

marks1 = 80
marks2 = 90
print(marks1 >= marks2)  # False


### Less than or equal to (<=): Checks if the left operand is less than or equal to the right operand.
e = 10
f = 15
print(e <= f)  # True

quantity1 = 5
quantity2 = 5
print(quantity1 <= quantity2)  # True

No comments:

Post a Comment