A python conditional statement determines the code block that executes by executing the result of one or more statements (true or false).
The Python program language specifies any non-0 and non-null (NULL) values of true,0 or NULL to FALSE.
In Python programming, if statements are used in the execution of control programs, in the basic form:
If judgment condition: Execute statement ... else: EXECUTE statement ....
Where the "judging condition" is established (not 0), the following statements are executed, and the execution content can be multiple lines, in order to be indented to differentiate the same range.
Else as an optional statement, you can execute the relevant statement when you need to execute the content when the condition is not true, as shown in the following example:
# coding=utf8# Example 1:if basic usage flag = Falsename = ' Luren ' if name = = ' Python ': # Determine if the variable is ' python ' flag = True # Set when condition is established Flag for true print ' welcome boss ' # and OUTPUT welcome message else: The output variable name when the print name # condition is not established
The output is:
>>> luren# Output Results
The judgment condition of the IF statement can be expressed by > (greater than), < (less than), = = (equals), >= (greater than or equal), <= (less than or equal).
When judging a condition for multiple values, you can use the following form:
If judgment condition 1: EXECUTE statement 1......elif judgment Condition 2: EXECUTE statement 2......elif judgment Condition 3: Execute statement 3......else: EXECUTE statement 4 ...
Python conditional statements