This Pass Statement lesson is for a beginner. Read the short notes, run each example, then change one name or number and run it again.
pass does nothing. It holds a place when Python requires a block and the real body is not written yet.
A comment cannot stand in for a block. pass can.
Example 1: Start here
Replace pass once you know what that branch should do.
score = 82 # a whole number
if score < 0: # run the indented lines only when this is true
pass # a placeholder, so the block is not empty
else: # runs when the test above was false
print(score)
Example 2: Leave a branch empty
pass means there is nothing to do in that branch.
score = 82 # a whole number
if score < 80: # run the indented lines only when this is true
pass # a placeholder, so the block is not empty
else: # runs when the test above was false
print("Pass")
Example 3: A function you will fill later
A function body cannot be empty. pass lets you define it now.
def save(): # define the function; it runs when you call it
pass # a placeholder, so the block is not empty
save() # call the function
print("defined")
Example 4: Skip in a loop
Low scores do nothing. High scores are printed.
for score in [82, 60, 91]: # repeat the indented lines once per value
if score < 80: # run the indented lines only when this is true
pass # a placeholder, so the block is not empty
else: # runs when the test above was false
print(score)
