python if conditional

1.if controlled conditions

  • Note that the write logic when is thinking what circumstances , in order to write the corresponding processing logic

  • But the code running time is like a funnel , like when to jump out the back of the statement will not be executed

  • In order to ensure the performance of our best to meet EDITORIAL most cases , you can normally can execute less code

  • Note that if and elif difference

# The student performance level to assess the difference excellent 
IF A> 90:         # greater than 90 
    Print ( ' excellent ' )
 elif A> 80:      # 90-80 as has already ruled out on a greater than 90 
    Print ( ' benign ' )
 elif A > 70 :
     Print ( ' in ' )  
 elif A> 60 :
     Print ( " pass " )
 the else :
     Print ( ' difference ' )

Four kinds of statements written 2.if

# Determines the length of a string 
A = " Hello Word " 
# method of a conventional method 
DEF func1 (A):
     IF len (A)>. 6 :
         return True
     the else :
         return False

# Method twenty-three mesh calculation 
DEF func2 (A):
     return True IF len (A)>. 6 the else False


# Method three table index 
DEF func3 (A):
     return [False, True] [len (A)>. 6] # When the list later returns true, then that is taken in front of a list of index values 1


# A method four logical operators 
DEF Func4 (A):
     return len (A)>. 6 and True or False    # If true and then later performs, or is not executed 
                                     # if it is false and does not perform the back, or will perform later

 

Guess you like

Origin www.cnblogs.com/su-sir/p/12467240.html