Python Conditional Statements
Python conditional statements determine the code block to be executed based on the execution result (True or False) of one or more statements.
You can simply understand the execution process of conditional statements through the following diagram:
The Python programming language specifies that any non-zero and non-null value is true, while 0 or null is false.
In Python programming, the if statement is used to control the execution of the program. The basic form is:
if 判断条件:
执行语句……
else:
执行语句……
When the "judgment condition" is true (non-zero), the subsequent statements are executed. The executed content can span multiple lines, distinguished by indentation to represent the same scope.
else is an optional statement. When you need to execute content when the condition is not true, you can execute the relevant statements.
GIF demonstration:

Specific examples are as follows:
Example
The output result is:
luren # 输出结果
The judgment condition of an if statement can use > (greater than), < (less than), == (equal to), >= (greater than or equal to), <= (less than or equal to) to express its relationship.
When the judgment condition has multiple values, the following form can be used:
if 判断条件1:
执行语句1……
elif 判断条件2:
执行语句2……
elif 判断条件3:
执行语句3……
else:
执行语句4……
An example is as follows:
Example
The output result is:
roadman # 输出结果
Since Python does not support the switch statement, multiple condition judgments can only be implemented with elif. If a judgment requires multiple conditions to be evaluated simultaneously, you can use or, which means the judgment condition succeeds when one of the two conditions is true; when using and, it means the judgment condition succeeds only when both conditions are true simultaneously.
Example
When an if statement has multiple conditions, parentheses can be used to distinguish the order of evaluation; the condition inside parentheses is evaluated first. In addition, the precedence of and and or is lower than comparison operators such as > (greater than) and < (less than). That is, without parentheses, greater than and less than are evaluated before and/or.
Simple Statement Group
You can also use an if conditional statement on the same line, as in the following example:
Example
The output of the above code execution is as follows:
变量 var 的值为100 Good bye!Other Extensions