Greater and less than
In the video, Hugo also talked about the less than and greater than signs, < and > in Python. You can combine them with an equals sign: <= and >=. Pay attention: <= is valid syntax, but =< is not.
All Python expressions in the following code chunk evaluate to True:
3 < 4
3 <= 4
"alpha" <= "beta"
Remember that for string comparison, Python determines the relationship based on alphabetical order.
This exercise is part of the course
Intermediate Python
Exercise instructions
- Write Python expressions, wrapped in a
print()function, to check whether:xis greater than or equal to-10.xhas already been defined for you."test"is less than or equal toy.yhas already been defined for you.Trueis greater thanFalse.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Comparison of integers
x = -3 * 6
# Comparison of strings
y = "test"
# Comparison of booleans