The Python programming language specifies that any non-0 and non-null (NULL) values are true, 0, or null is false.
In Python programming, if statements are used in the execution of control programs, in the basic form:
if Judging 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 is an optional statement that can be executed when the condition is not true, for example:
# example 1:if basic usage flag = Falsename = " luren " if name = = python ' : # Determine if the variable is " python " flag = true # when the condition is set to true print " welcome boss " else : Print name # condition is not valid when output variable name
Output Result: Luren
The judgment condition of the IF statement can be used >, <, = =, >=, <=. You can use the following syntax when judging a condition as multiple values
if Judging condition 1: executing statement 1......elif judging condition 2: executing statement 2......elif judging condition 3: executing statement 3 ... Else : EXECUTE statement 4 ...
Since Python does not support switch statements, multiple judgment conditions can be implemented with elif, and if it is judged that multiple conditions need to be judged simultaneously, you can use or and and, in the operation judgment of the OR and and, follow and take precedence over or in operations already x and Y X=true equals y, x or y x=true equals x rule.
num=-1 ; if num<0 or Num>10 print ( " true " ) else : Print ( " Span style= "COLOR: #800000" >false ")
In the case of Python
First, the and priority is greater than or when no parentheses are added.
Second, the value of x or y may only be x or Y. X is True is X, X is False, Y
Third, the value of x and Y may only be x or Y. X is True is Y, X is False is x obviously,
1 5 4 4 4 1 is true and the value is 1
For, (15454, 1 true, value 4
Python conditional statements