Example
Positional and Keyword Arguments
Difference between positional and keyword arguments. Flexible function calling.
Showing 1–10 of 21
Example
Difference between positional and keyword arguments. Flexible function calling.
Quiz
Free beginner quiz on Python functions: 15 questions on def, return, arguments, default values, *args, scope and docstrings. Instant answers.
Challenge
…find which parameter got which value, fix it with keyword arguments, then make calls that can't be swapped.
Challenge
Extend format_log() from "Log formatter function" with **fields, so any extra keyword arguments are added to the line as key=value pairs, then pass whole dicts of fields into it with ** at the call.
Example
Parameters allow passing data to functions. Functions become more flexible.
Example
Operator * allows accepting any number of positional arguments.
Example
Operator ** allows accepting any number of keyword arguments.
Challenge
…pass from the database, sometimes just two numbers. A function that wants a list makes every one of those calls a little clumsier than it needs to be. Write an average that takes the values as they…
Challenge
…where waiting is worse than failing. Give the uplink function sensible defaults, then add an option without touching any of its callers. Defaults Give retries a default of 3 and timeout a default of…
Quiz
…quiz on Python *args and **kwargs: 15 questions on extra arguments, tuples, dictionaries, and * and ** in calls. Instant answers.