Judgment statement in python
The Python programming language specifies that any non-0 and non-null (null) values are true, and 0 or null values are false. In Python programming, if statements are used to control program execution. The basic form is: if judgment condition: execution statement ...... Else: Execute the statement ...... When the "judgment condition" is set to a non-zero value, the following statement is executed, and the execution content can be multiple rows, which are indented to indicate the same range. Else is an optional statement. You can execute related statements when the conditions are not met. For example: # Example 1: Basic if usage #! /Usr/bin/python #-*-coding: UTF-8-*-flag = Falsename = 'luren' if name = 'python ': # determine whether the variable is 'python' flag = True # When the condition is set, set the flag to True print 'Welcome boss' # and output the welcome information else: print name # When the condition is not met, the output variable name output result is: >>> luren # The output result. if statement judgment conditions can be> (greater than), <(less), = (equal to), >=( greater than or equal to), and <= (less than or equal to) indicate the relationship. If the condition is multiple values, use the following form: if condition 1: Execute Statement 1 ...... Elif condition 2: Statement 2 ...... Elif Condition 3: Statement 3 ...... Else: Execute Statement 4 ...... # Example 2: elif usage num = 5 if num = 3: # determine the num value print 'boss' elif num = 2: print 'user' elif num = 1: print 'worker' elif num <0: # print 'error' else: print 'roadman 'If the value is less than zero # output when none of the conditions are met