Learning outcomes
By the end of this lecture, you should be able to:- distinguish positional and keyword arguments
- use default arguments correctly
- understand
*argsand**kwargsat introductory level
Positional arguments
Keyword arguments
Default arguments
Variable-length positional arguments
Variable-length keyword arguments
Common rules
- positional arguments must come before keyword arguments in function call
- default arguments should be placed after required ones in definition
Exam hints and traps
- missing required argument raises
TypeError - too many arguments also raise
TypeError - default value is used only when caller does not supply that argument
Quick practice
- Write function with default argument
country="India". - Call a function once with positional and once with keyword style.
- Explain what
*numscollects.
