Variable Function Arguments in Python. *args, **kwargs

The use of args and kwargs in Python has often confounded me.

Few notes from Data Science From Stratch:

  • The asterisk performs argument unpacking, which uses the elements of pairs as
    individual arguments
  • That is, when we define a function like this, args is a tuple of its unnamed arguments and kwargs is a dict of its named arguments.

 

Code:

args_kwargs

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s