Raspberry Selection Structure
In previous lessons, we have learned sequence structure and loop structure in the three basic program structures. The final one is selection structure. The selection structure makes a judgement according to the defined conditions and executes the corresponding operation according to the result of the judgment. For example, after judging the weather, we choose to take an umbrella if it’s raining, and vice versa. In Python, you can use the “if... else" statement to write such evaluative condition in the following three forms.
“if" statement
This is the simplest conditional judgment. If the expression is true, the code block will be executed. If the expression is not true, nothing will be done. For example, to take an umbrella if it's raining, but do nothing if not.1 if expression:
2 code block