Today I will share with you the use of IF statements in Python
First we look at a flow chart of IF statement processing:
The operating principle of the IF statement is: given the conditions, decide what to do next? If the condition is true, execute the content of the decision condition code block, and exit if it is false.
Before we learn, let’s take a look at true and false in Python: In python, any non-zero, non-empty object is true, and everything except True and None is false.
Let’s take notes:
1. Any non-zero and non-empty object is interpreted as True
2. Numbers 0. Both empty objects and special objects None are false and interpreted as False
3. Comparison and equality tests will be applied to the data structure
4. The return value is True or False
Look at a few examples:
The basic composition of the if statement:
For example:
The above is the detailed content of How to write the if statement in python. For more information, please follow other related articles on the PHP Chinese website!