Python Pop Quiz - Positional Arguments
Python functions can take in several different types of arguments. What are the different argument types called?
If you don’t know, you should review the following:
Positional arguments
Keyword arguments
This information may help you solve the quiz, or it may confuse you more. Read the next section when you’re ready to take a crack at it!
The Quiz
How do you call a function like this? Or can you?
A) positional(’Mike’, 17, key=’test’)
B) positional(’Mike’, 17, 2, b=3, key=’test’)
C) positional(’Mike’, 2, b=3, key=’test’)
D) None of the above
Hint
The code above is valid Python syntax starting with Python 3.8. If you get stuck, you might want to look up PEP 570, but only do that as a last resort!
The Answer
B) positional(’Mike’, 17, 2, b=3, key=’test’)
Explanation
The first two parameters, name and age are positional only. That means you can’t pass them in as keyword arguments, which is why you would see a TypeError if you tried to pass either of them in as keywords. The arguments, a and b can be positional or keyword, whereas key, is keyword-only.
The forward slash, /, indicates to Python that all arguments before the forward slash as positional-only arguments. Anything following the forward slash is positional or keyword arguments up to the asterisk. The asterisk indicates that everything following it is keyword-only arguments.
That means that B is the correct way to call this function. There are other ways, of course. But they aren’t listed here. Experiment with it yourself and see what alternative methods you can come up with to call this function!



