Function Parameters and Argument Lists
You'll learn: How to design cleaner, more maintainable function signatures by following best practices for parameter counts, types, and organization.
The Core Problem
Functions are like restaurant orders: the more complicated the request, the more likely something goes wrong. When a function takes too many parameters, uses confusing flag arguments, or mixes unrelated data, it becomes hard to understand, test, and use correctly.
Minimize Parameter Count
Aim for 0–3 parameters. More than that signals your function might be doing too much or that related data should be grouped together.
# Hard to remember order and meaning
def create_user(name, email, age, country, newsletter, premium):
pass
# Better: group related data
def create_user(user_profile, preferences):
pass
Avoid Flag Arguments
Boolean flags tell a function to do two different things, violating the Single Responsibility Principle you learned earlier. They force readers to understand multiple code paths.
# Confusing: what does True mean?
render_page(data, True)
# Clear: split into distinct functions
render_page_with_sidebar(data)
render_page_without_sidebar(data)
Use Objects for Multiple Values
When you need to pass several related values, bundle them into an object or data structure. This improves readability and makes adding related data easier later without changing every function call.
# Cluttered parameter list
def draw_rectangle(x, y, width, height, color, border_width):
pass
# Clean: related values grouped
def draw_rectangle(position, dimensions, style):
pass
Key Takeaway: Keep functions simple with 0–3 parameters, avoid boolean flags that branch behavior, and group related data into objects rather than passing individual values—your future self and teammates will thank you.