Skip to content

expanding explanation from three to four extended args syntax #237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions args_and_kwargs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,29 @@ function. Here's how to do it:
arg2: two
arg3: 3

**Order of using \*args \*\*kwargs and formal args**
**Order of using \*args \*\*kwargs and formal positional and keyword args**

So if you want to use all three of these in functions then the order is
So if you want to use all four of these in functions then the order is

.. code:: python

some_func(fargs, *args, **kwargs)
some_func(fargs, *args, key=value, **kwargs)

def another_func(a, b, *args, fruit="banana", car="vw", **kwargs):
# do something here
pass

# call it elegantly
another_func(1, 2, 3, 4, 5, 6, fruit="mango", car="fiat", animal="lion")

# formal positional arguments: a=1, b=2
# *args is a tuple (3,4,5,6,)
# formal keyword arguments: fruit and car
# **kwargs as a dict {animal: "lion"}

Theoretically \*args and \*\*kwargs can be become how long as your memory (but
not infinite). Exceeding your system's available memory limits can raise a
MemoryError exception.

When to use them?
^^^^^^^^^^^^^^^^^
Expand Down