Conditionals
If statement
Here are a few things to notice about the if statement:
The
ifstatement starts withif, it continues withprice == 0.0and it ends with:.Use the
==operator to check if the price is equal to0.0. Don't confuse==with=(=is a variable assignment operator in Python; we use it to assign values to variables — it doesn't tell us anything about equality).Indent
ratings.append(rating)four spaces to the right relative to theifstatement.

Multiple conditions
we can combine two or more conditions together into a single if statement using the and keyword. In the two diagrams below, we can use and to simultaneously check whether an app is both free and has a gaming genre.
Notice above that code like app_1_price == 0 and app_1_genre == 'Games' outputs a single Boolean value.

Using or in conditions
else statement
The code within the body of an else clause executes only if the if statement that precedes it resolves to False
else if (elif)
The code within the body of an elif clause executes only under the following circumstances:
The preceding
ifstatement (or the other precedingelifclauses) resolves toFalse; andThe condition specified after the
elifkeyword evaluates toTrue.
Comparison Operators

Last updated