Syntax
passExamples
Placeholder Function
Stubbing out a function you plan to implement later.
def send_email(to, subject, body):
pass # TODO: implement email sending logic
def calculate_discount(price):
pass # not yet implemented
send_email("user@example.com", "Hi", "Hello there") # runs, does nothing yetEmpty Class
Defining a class body with no attributes or methods yet.
class CustomError(Exception):
pass # inherits everything from Exception, adds nothing new
raise CustomError("Something went wrong")Placeholder in Conditional Branches
Intentionally leaving one branch of an if statement empty while working on the others.
status = "pending"
if status == "approved":
print("Processing order")
elif status == "pending":
pass # intentionally no action yet
elif status == "rejected":
print("Order cancelled")Best practices
- Use pass as a temporary placeholder while sketching out code structure, then replace it with real logic
- Prefer pass over leaving a block genuinely empty, since Python's syntax doesn't allow empty blocks at all
- Use pass for minimal custom exception classes that only need a distinct type, not new behavior
- Don't forget to come back and implement code left as pass - consider adding a comment or TODO alongside it
At a glance
- Purpose
- Scripting and general-purpose applications
- File extension
- .py
- Runs in
- Python interpreter
- Usually used with
- Python standard library and packages
Specifications & further reading
Related Python documentation
if
The if statement is Python's primary conditional control structure. It allows your program to make decisions by executing different code blocks based on whether a condition is True or False. The if statement is fundamental to creating dynamic, responsive programs that can adapt their behavior based on various conditions, user input, or data states.for
The for loop in Python is used to iterate over sequences like lists, tuples, strings, or any iterable object. Unlike traditional for loops in other languages that use counters, Python's for loop is more like a "for each" loop, automatically handling the iteration details. It's one of the most commonly used constructs in Python for processing collections and repeating actions.while
The while loop repeats a block of code as long as its condition remains True. Unlike a for loop, which iterates a known number of times over a sequence, a while loop is ideal when you don't know in advance how many iterations you'll need - like waiting for valid user input or running until some external condition changes. A while loop can also have an optional else clause that runs if the loop finishes normally, without hitting a break.break and continue
break and continue give you fine-grained control over loop execution. break immediately exits the nearest enclosing loop entirely, skipping any remaining iterations. continue skips just the rest of the current iteration and jumps straight to the next one, without exiting the loop. Both work inside for and while loops.
The if statement is Python's primary conditional control structure. It allows your program to make decisions by executing different code blocks based on whether a condition is True or False. The if statement is fundamental to creating dynamic, responsive programs that can adapt their behavior based on various conditions, user input, or data states.for
The for loop in Python is used to iterate over sequences like lists, tuples, strings, or any iterable object. Unlike traditional for loops in other languages that use counters, Python's for loop is more like a "for each" loop, automatically handling the iteration details. It's one of the most commonly used constructs in Python for processing collections and repeating actions.while
The while loop repeats a block of code as long as its condition remains True. Unlike a for loop, which iterates a known number of times over a sequence, a while loop is ideal when you don't know in advance how many iterations you'll need - like waiting for valid user input or running until some external condition changes. A while loop can also have an optional else clause that runs if the loop finishes normally, without hitting a break.break and continue
break and continue give you fine-grained control over loop execution. break immediately exits the nearest enclosing loop entirely, skipping any remaining iterations. continue skips just the rest of the current iteration and jumps straight to the next one, without exiting the loop. Both work inside for and while loops.