Python study notes - controlled conditions

The if statement

The general form of Python if statement is as follows:

if condition_1:
    statement_block_1
elif condition_2:
    statement_block_2
else:
    statement_block_3

If "condition_1" to True will perform "statement_block_1" block statement
if "condition_1" to False, the determination "condition_2"
If "condition_2" to True will perform "statement_block_2" block statement
if "condition_2" False, the execution "statement_block_3" block statement
(0 to False, nonzero is True, negative number is non-zero is True)

Instead of using Python elif else if, so if statement keyword is: if - elif - else.

Note:
1, each of the conditions to be used later colon: indicates the following condition is satisfied after the statement block to be executed.
2, using indentation divided statement blocks, the number of statements in the same indentation together to form a block.
3, there is no switch in Python - case statement.

Operators description
< Less than
<= less than or equal to
> more than the
>= greater than or equal to
== Equal, compare two values ​​are equal
!= not equal to

Python3 controlled conditions

Published 11 original articles · won praise 3 · Views 932

Guess you like

Origin blog.csdn.net/qq_36551226/article/details/104137893