![]() ![]() |
Conceptual Review (page 22 of 55) |
The simplest conditional is the if statement. The Boolean expression after the if statement is called the condition. Python supports the standard logical conditions.
1. Equals: x == y
2. Not Equals: x != y
3. Less than: x < y
4. Less than or equal to: x <= y
5. Greater than: x > y
6. Greater than or equal to: x >= y
Recall that we use a single "=" for assignment (i.e., x = 6) but the double "==" for comparison (i.e., x==6 would test if the value of x is equal to 6). Entering x=6 in a condition will result in a traceback because python cannot perform an assignment in a conditon. Instead, python can only evaluate whether a condition is True or False, which requires x==6.
Also, notice the not equal operator is != instead of <>, which is used in other programming languages.