There may be a situation when you want to check other conditions after a condition resolves to true. In this case, you can use a nested if structure.
In a nested IF statement structure, you can have another if ... else structure inside an if ... else structure. elif. elif.
Grammar:
The syntax for nesting if...elif...else structures can be:
If expression1: statement (s) if expression2: statement (s) elif Expression3: statement (s) Else statement (s) elif Expression4: statement (s) Else: statement (s)
The limit, please correct me. Please be sure to indicate the source of the reprint.
There may be a situation when you want to check other conditions after a condition resolves to true. In this case, you can use a nested if structure.
In a nested IF statement structure, you can have another if ... else structure inside an if ... else structure. elif. elif.
Grammar:
The syntax for nesting if...elif...else structures can be:
If expression1: statement (s) if expression2: statement (s) elif Expression3: statement (s) Else statement (s) elif Expression4: statement (s) Else: statement (s)
For example:
#!/usr/bin/pythonvar = 100if var < $: print "Expression value is less than" if var = =: print "Whi CH is elif var = =: print "which is" elif var = =: print "which is" Elif var <: Print "expression value is less than" else: print "Could not" find true Expression "print" Good bye! "
When executing the above code, it produces the following result:
Expression value is less than 200Which is 100Good bye!