Python nested if statements in Python - Tutorialspoint
[Pages:1]PYTHON NESTED IF STATEMENTS
Copyright ?
There may be a situation when you want to check for another condition after a condition resolves to true. In such a situation, you can use the nested if construct.
In a nested if construct, you can have an if...elif...else construct inside another if...elif...else construct.
Syntax:
The syntax of the nested if...elif...else construct may be:
if expression1: statem ent(s) if expression2: statem ent(s) elif expression3: statem ent(s) else statem ent(s)
elif expression4: statem ent(s)
else: statem ent(s)
Example:
#!/usr/bin/python
var = 100 if var < 200:
print "Expression value is less than 200" if var == 150:
print "Which is 150" elif var == 100:
print "Which is 100" elif var == 50:
print "Which is 50" elif var < 50:
print "Expression value is less than 50" else:
print "Could not find true expression"
print "Good bye!"
When the above code is executed, it produces following result:
Expression value is less than 200 Which is 100 Good bye!
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- python selection if else basic selection statement
- lecture 8 conditionals control flow special one
- how to make if statements in python
- python if else rxjs ggplot2 python data persistence
- python conditional statements
- conditional statements in python
- python nested if statements in python tutorialspoint
- loops and conditionals purdue university
Related searches
- multiple if statements in tableau
- nested if statement in tableau
- nested if statements in excel with dates
- embedded if statements in excel
- multiple if statements in excel
- nested if functions in excel
- if statements in verilog
- if statements in excel color change
- multiple return statements in python function
- python check if string in list
- python check if key in dictionary
- if statement in python example