Conditional statements in Python, the IF statement is used for conditional judgment, in the following format:If you want to judge the condition:things to do when the conditions are set...It is important to indent in Python, to indent 4 spaces in the run content of the IF condition statement Walkthrough-Judging age Requirements
- Define an integer variable to record age
- Determine if you are over 18 years old (>=)
- If you are over 18 years old, allow access to Internet cafes
Output Results
If the else processing condition is not satisfiedIf you want to judge the condition:things to do when the conditions are set...Else:things to do when the conditions are not setThat is, execute else when the if decision is not met, and execute the code output in else. The contents of the preceding input (), and the assignment variable are used here. Oh, you can look at the previous content without understanding.
Supplement:
- When the numeric data is judged directly, the non-0 number is true and 0 is false
- Do you remember the bool type? 1 is true,0 is false yo!
Elif
- A pair of if and else allows the code to execute two different results
- But in development, you might want to perform multiple results in parallel, and you can use Elif
- The syntax format is as follows:
if condition 1:condition 1 code that satisfies execution...elif Condition 2:code to execute when condition 2 is met...elif Condition 3:code to execute when condition 3 is met...Else:code that executes when none of the above conditions are metWhen multi-conditional judgment is used,
Note that both elif and else must be used in conjunction with if and cannot be used alone
Learning the path to Python: conditional statements