-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path08 - NESTED CONDTION
More file actions
34 lines (27 loc) · 856 Bytes
/
08 - NESTED CONDTION
File metadata and controls
34 lines (27 loc) · 856 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Python also provides nested conditional statements...
which means a condtion within a condition
Nested if statements means an if statement inside another if statement.
Yes, Python allows us to nest if statements within if statements.
i.e, we can place an if statement inside another if statement.
if (condition1):
# Executes when condition1 is true
if (condition2):
# Executes when condition2 is true
# if Block is end here
# if Block is end here
EXAMPLE PROGRAM :
i = 10
if (i == 10):
# First if statement
if (i < 15):
print ("i is smaller than 15")
# Nested - if statement
# Will only be executed if statement above
# it is true
if (i < 12):
print ("i is smaller than 12 too")
else:
print ("i is greater than 15")
OUTPUT:
i is smaller than 15
i is smaller than 12 too