Let’s check out some exercises that will help understand pass statement better.

Exercise 20-a

Place a pass statement so that if block won't throw an error.


pass statement is a placeholder in Python so that certain structures can be left unfinished without throwing an error.

if len(name) > 0:
print(name)
else:
pass

Exercise 20-b

Place pass statement in your function so that you can leave it unfinished and it doesn't throw an error.


pass statement is a placeholder in Python so that certain structures can be left unfinished without throwing an error.

def f_1 (x):
pass

Exercise 20-c

Put a pass statement in your for loop to avoid an error.


pass statement is a placeholder in Python so that certain structures can be left unfinished without throwing an error.

for i in lst:
pass

 

Exercise 20-d

Put a pass statement in the while loop so it doesn't throw an error.


pass statement is a placeholder in Python so that certain structures can be left unfinished without throwing an error.

i=0
while i<20:
i = i+1
if i**2<49:
print(i*100)
else:
pass