Learn
Let’s start with the simplest aspect of control flow: comparators. There are six:
Equal to (==
)
>>> 2 == 2 True >>> 2 == 5 False
Not equal to (!=
)
>>> 2 != 5 True >>> 2 != 2 False
Less than (<
)
>>> 2 < 5 True >>> 5 < 2 False
Less than or equal to (<=
)
>>> 2 <= 2 True >>> 5 <= 2 False
Greater than (>
)
>>> 5 > 2 True >>> 2 > 5 False
Greater than or equal to (>=
)
>>> 5 >= 5 True >>> 2 >= 5 False
Comparators check if a value is (or is not) equal to, greater than (or equal to), or less than (or equal to) another value.
Note that ==
compares whether two things are equal, and =
assigns a value to a variable.
Instructions
1.
Set each variable to True
or False
depending on what you think the result will be. For example, 1 < 2
will be True
, because one is less than two.
- Set
bool_one
equal to the result of17 < 328
- Set
bool_two
equal to the result of100 == (2 * 50)
- Set
bool_three
equal to the result of19 <= 19
- Set
bool_four
equal to the result of-22 >= -18
- Set
bool_five
equal to the result of99 != (98 + 1)
Take this course for free
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.