2.2. Comparisons#
In Python, when we compare values, the results return a Boolean.
x = 10
print(x < 0)
False
We can compare values using the following operators:
<less than>greater than<=less than or equal to>=greater than or equal to==check values are equal!=check values are not equal
2.2.1. Exercises#
Question 1
Does the following program return True or False?
x = 2
print(x > 3)
lock
This solution is locked.
Question 2
Does the following program return True or False?
x = 7.2
print(x <= 7.2)
lock
This solution is locked.
Question 3
Does the following program return True or False?
x = 2 + 4
print(x == 6)
lock
This solution is locked.
Question 4
Does the following program return True or False?
x = 4*3
print(x != 5)
lock
This solution is locked.
Question 5
Does the following program return True or False?
x = 2**2
print(x != 4)
lock
This solution is locked.
Question 6
Does the following program return True or False?
x = 10
print((x - 1) % 3 == 0 )
lock
This solution is locked.
Question 7
Does the following program return True or False?
x = 'red'
print(x == 'red')
lock
This solution is locked.