control statements if python

 

The if statement

grammar:

if Condition 1: 
    a block of statements 1 
elif Condition 2: 
    a block of statements 2 
the else : 
    statement block 3
  • If the condition 1 is True, then execute the statement 1;
  • If the condition 1 is False, statement 2 is determined, if the statement 2 is True, the statement 2 is executed;
  • 2 If the condition is False, then the statement is executed 3.

if the operator common operations:

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

 

 

 

 

 

 

if nested

grammar:

if the expression 1: 
    Statement 1 
    if the expression 2: 
        Statement 2 
    elif Expression 3: 
        Statement 3 
    the else : 
        statement 4 
elif expression 4: 
    statements. 5 
the else : 
    Statement 6

Implementation process:

1 If the expression is True, then execute the statement 1, 2 if the expression is True, the statement 2 is executed; 2 if the expression is False, determining the expression 3, 3 if the expression is True, then execute the statement 3; if the expression formula 3 is False, then execute the statement 4;

1 if the expression is False, the determination expression 4, 4 if the expression is True, then execute the statement 5;

4 If the expression is False, then the statement is executed 6.

 

Guess you like

Origin www.cnblogs.com/1510152012huang/p/11239087.html