Python pass Keyword
A null statement, meaning a statement that will do nothing,
def myFunction: pass
A code block, such as a for loop, while loop, or function, cannot be empty. The pass keyword gives you something to put in a block that is a placeholder for later coding so that it "passes" syntax checking.
Examples
The pass
keyword is simply a placeholder instruction. It does nothing other than acts as a
placeholder in situations where you need to have something and you'll come around to the actual implementation later.
def complexCalculation(a,b): pass # I'll complete this function later... a = 1 b = 10 complexCalculation(a,b)
Here, you're sketching out some code but haven't completed the implementation. You
can define the function but you can't have a function that is empty or only contains
a comment. So, use the pass
statement to keep Python happy while you work on finishing
things up.
Notes
Be careful - the function will still run the code, it simply ignores the pass statements:
def todo(): a = 5 pass print(a) todo()
Output
5