Get Started

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 is a part of the course

“Intermediate Python”

View Course

Exercise instructions

  • Write Python expressions, wrapped in a print() function, to check whether:
    • x is greater than or equal to -10. x has already been defined for you.
    • "test" is less than or equal to y. y has already been defined for you.
    • True is greater than False.

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

This exercise is part of the course

Intermediate Python

BeginnerSkill Level
4.6+
772 reviews

Level up your data science skills by creating visualizations using Matplotlib and manipulating DataFrames with pandas.

Boolean logic is the foundation of decision-making in Python programs. Learn about different comparison operators, how to combine them with Boolean operators, and how to use the Boolean outcomes in control structures. You'll also learn to filter data in pandas DataFrames using logic.

Exercise 1: Comparison OperatorsExercise 2: EqualityExercise 3: Greater and less than
Exercise 4: Compare arraysExercise 5: Boolean OperatorsExercise 6: and, or, not (1)Exercise 7: and, or, not (2)Exercise 8: Boolean operators with NumPyExercise 9: if, elif, elseExercise 10: WarmupExercise 11: ifExercise 12: Add elseExercise 13: Customize further: elifExercise 14: Filtering pandas DataFramesExercise 15: Driving right (1)Exercise 16: Driving right (2)Exercise 17: Cars per capita (1)Exercise 18: Cars per capita (2)

What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.

Start Learning for Free