Challenge
Swapped arguments
…find which parameter got which value, fix it with keyword arguments, then make calls that can't be swapped.
Showing 1–10 of 25
Challenge
…find which parameter got which value, fix it with keyword arguments, then make calls that can't be swapped.
Example
Difference between positional and keyword arguments. Flexible function calling.
Example
Operator ** allows accepting any number of keyword arguments.
Example
Operator * allows accepting any number of positional arguments.
Challenge
…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.
Quiz
…quiz on Python *args and **kwargs: 15 questions on extra arguments, tuples, dictionaries, and * and ** in calls. Instant answers.
Quiz
…quiz on Python functions: 15 questions on def, return, arguments, default values, *args, scope and docstrings. Instant answers.
Example
Parameters allow passing data to functions. Functions become more flexible.
Challenge
Make abort(reason, *, confirm) refuse to run unless confirm=True is passed by name: a bare * makes confirm keyword-only and required, then an is True check refuses values that are merely truthy, such…
Challenge
…passes the five readings as five separate arguments. An option after the values Add a rounding option, decimals=1 , after *values , and return None when there are no values at all. Round the whole…