Search the courses, subjects, tracks, games and features, or jump straight to a page.
3 cards from this section. Quick, good the night before a test.
Write a function that uses a default argument for a country.
Think of a common value for the country.
What will be the output of this function: def test(a, b=5): return a + b; print(test(3))?
Consider what happens when the default value is used.
What is a default argument in Python?
Think about the function's behavior when no value is given for a parameter.
True or False: A mutable default argument can lead to surprising outcomes in a function's operation.
Consider functions with lists or dictionaries as defaults.
Create a function that takes a name and a default age, ensuring that age defaults to 21 if not supplied. Create two different instances of the function and illustrate how it works.
Experiment with calling your function to see how defaults work.
Describe what could go wrong if you use a list as a default argument in a function. Illustrate with code.
Test this out with several calls to the function.
6 more questions in this section. Enroll free to practise them all.
Enroll free