Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is the correct order of arguments in a Python function definition?
The correct order is: positional arguments, default arguments, *args (variable positional arguments), keyword-only arguments, and **kwargs (variable keyword arguments).
Click to reveal answer
beginner
Why must positional arguments come before default arguments in Python functions?
Because Python assigns values to arguments in order. If a default argument came before a positional one, Python wouldn't know which value belongs where.
Click to reveal answer
beginner
What happens if you put a default argument before a positional argument in a function definition?
Python will raise a SyntaxError because default arguments must follow positional arguments.
Click to reveal answer
intermediate
What is the role of *args and **kwargs in argument order?
*args collects extra positional arguments as a tuple, and **kwargs collects extra keyword arguments as a dictionary. They must come after positional and default arguments.
Click to reveal answer
intermediate
How do keyword-only arguments fit into the argument order?
Keyword-only arguments come after *args and must be specified by name when calling the function. They can have default values.
Click to reveal answer
Which of the following is the correct order of arguments in a Python function?
The correct order is positional, default, *args, keyword-only, then **kwargs.
What error occurs if a default argument is placed before a positional argument?
ASyntaxError
BTypeError
CValueError
DNameError
✗ Incorrect
Python raises a SyntaxError if default arguments come before positional arguments.
What does *args collect in a function?
AOnly keyword-only arguments
BExtra keyword arguments as a dictionary
COnly default arguments
DExtra positional arguments as a tuple
✗ Incorrect
*args collects extra positional arguments as a tuple.
Where do keyword-only arguments appear in the argument order?
ABefore default arguments
BBefore positional arguments
CAfter *args and before **kwargs
DAfter **kwargs
✗ Incorrect
Keyword-only arguments come after *args and before **kwargs.
Which argument type must be specified by name when calling a function?
ADefault arguments
BKeyword-only arguments
CPositional arguments
D*args
✗ Incorrect
Keyword-only arguments must be specified by name when calling the function.
Explain the correct order of arguments in a Python function and why this order matters.
Think about how Python matches values to parameters when you call a function.
You got /6 concepts.
Describe the roles of *args and **kwargs in function arguments and their position in the argument order.
Consider how functions handle extra arguments beyond those explicitly named.
You got /5 concepts.
Practice
(1/5)
1.
Which of the following correctly describes the order of arguments in a Python function definition?
easy
A. Positional-only, positional-or-keyword, keyword-only
B. Keyword-only, positional-only, positional-or-keyword
C. Positional-or-keyword, keyword-only, positional-only
D. Positional-or-keyword, positional-only, keyword-only
Solution
Step 1: Recall argument order rules
Python functions must define arguments in the order: positional-only, positional-or-keyword, then keyword-only.
Step 2: Match the correct order
Positional-only, positional-or-keyword, keyword-only matches this exact order, others do not.
Final Answer:
Positional-only, positional-or-keyword, keyword-only -> Option A
Quick Check:
Argument order = Positional-only, positional-or-keyword, keyword-only [OK]
Hint: Remember: positional-only first, then normal, then keyword-only [OK]
Common Mistakes:
Confusing keyword-only and positional-only order
Thinking positional-or-keyword comes first
Ignoring positional-only arguments
2.
Which of the following function definitions is syntactically correct in Python?
def example(a, /, b, *, c):
pass
easy
A. def example(a, /, b, *, c): pass
B. def example(a, b, *, /, c): pass
C. def example(a, *, b, /, c): pass
D. def example(/, a, b, *, c): pass
Solution
Step 1: Understand syntax for positional-only and keyword-only
The slash (/) marks positional-only arguments before it, and the asterisk (*) marks keyword-only arguments after it.
Step 2: Check each option's order
def example(a, /, b, *, c): pass correctly places a before / (positional-only), b as positional-or-keyword, and c after * (keyword-only). Others have invalid order or misplaced / and *.
Final Answer:
def example(a, /, b, *, c): pass -> Option A
Quick Check:
Syntax with / and * correct = def example(a, /, b, *, c): pass [OK]
Hint: Slash (/) before positional-only, star (*) before keyword-only [OK]
A. TypeError: missing required keyword-only argument 'c'
B. 1 2 3
C. TypeError: positional argument after keyword argument
D. SyntaxError
Solution
Step 1: Understand argument passing
a is positional-only, so must be passed by position (1). b is positional-or-keyword, passed by position (2). c is keyword-only, passed as c=3.
Step 2: Check function call validity and output
All arguments are passed correctly. The print outputs the values: 1 2 3.
Final Answer:
1 2 3 -> Option B
Quick Check:
func(1, 2, c=3) prints 1 2 3 [OK]
Hint: Positional-only args by position, keyword-only by name [OK]
Common Mistakes:
Passing positional-only argument by keyword
Passing keyword-only argument positionally
Confusing argument order in call
4.
Identify the error in this function call:
def f(x, /, y, *, z):
return x + y + z
f(x=1, y=2, z=3)
medium
A. No error, returns 6
B. TypeError: missing required positional argument y
C. SyntaxError: invalid function call
D. TypeError: x is positional-only and cannot be passed as keyword
Solution
Step 1: Check argument types in definition
x is positional-only (before /), y is positional-or-keyword, z is keyword-only (after *).
Step 2: Analyze function call
Calling f(x=1, y=2, z=3) tries to pass x by keyword, which is not allowed for positional-only arguments, causing a TypeError.
Final Answer:
TypeError: x is positional-only and cannot be passed as keyword -> Option D
Quick Check:
Positional-only args cannot be keyword = TypeError [OK]
Hint: Positional-only args can't be named in calls [OK]
Common Mistakes:
Passing positional-only argument by keyword
Thinking all arguments can be named
Ignoring the / marker meaning
5.
You want to define a function that takes exactly two positional-only arguments, one positional-or-keyword argument, and two keyword-only arguments. Which of these definitions is correct?