Example
Positional and Keyword Arguments
Difference between positional and keyword arguments. Flexible function calling.
Showing 1–10 of 12
Example
Difference between positional and keyword arguments. Flexible function calling.
Example
Operator ** allows accepting any number of keyword arguments.
Challenge
…line, find which parameter got which value, fix it with keyword arguments, then make calls that can't be swapped.
Challenge
…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.
Quiz
…quiz on Python *args and **kwargs: 15 questions on extra arguments, tuples, dictionaries, and * and ** in calls. Instant answers.
Challenge
…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 as "yes".
Challenge
…loose values and with a list unpacked by *, then add a keyword-only decimals option after *values and return None when there are no values.
Quiz
…quiz on Python functions: 15 questions on def, return, arguments, default values, *args, scope and docstrings. Instant answers.
Challenge
Give send_command(cmd, retries=3, timeout=5.0) default values so callers only pass what differs, call it three different ways, then add a new priority parameter without breaking any existing call.
Article Python Fundamentals
…hasn't heard of it yet. Passing data in: parameters and arguments A function that does exactly the same thing every time has its uses, but most of the time you want to hand it some information and let…