Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Python args and kwargs: Demystified (Summary)

Download

Sample Code (.zip)

5.8 KB

Download

Course Slides (PDF)

261.9 KB

tsusadivyago on Jan. 8, 2020

We learn python basic properly in this site :)

Mallesham Yamulla on Jan. 13, 2020

Many Thanks for this video turorial, it’ a great refresher for args and kwargs.

Pygator on Jan. 18, 2020

Really liked the list merging and dictionary merging examples!

ColmC on Jan. 18, 2020

Very handy. Thanks!

alanhrosenthal on Feb. 3, 2020

very good!

Suggestion - maybe add how to pass arguments from the command line including variable numbers of args from the command line.

Geir Arne Hjelle RP Team on Feb. 3, 2020

Alan, thanks for the suggestion.

We actually have a full article coming out on Wednesday on the topic of command line arguments!

You should be able to see it already in your membership preview: click your profile picture, then notifications. Scroll down to find Python Command Line Arguments

mohammedayub44 on Feb. 25, 2020

No hard-coded values ever in my scripts again ! Nice tricks with just one operator. It would be good to explain runtime complexity as well when using such iterables.

Eriberto on March 13, 2020

Any more practical use-cases for these examples? Just re learning these things again.

pshapard on April 8, 2020

Rich, thanks for the video course. I understand what’s going on the args and kwargs. What if you have a simple function like the below. How would implement args to this function.

def get_auth_token(): login = LoginCreds(ip, api, username, password) try: auth = login.LoginToken(ip, api, username, password) return auth except ConnectionError as e: logging.info(“Could not connect to host”) sys.exit(0)

pshapard on April 8, 2020

regarding my last post. I have written scripts using the requests module extensively. The responses are large json the jsons are a dictionary of dictionaries. I parse those to get certain information, such as,

permittedInterconnectTypeUri = [‘/rest/interconnect-types/ce3381c9-c948-4c71-946a-8893163ae4a6’] networkUris = [‘/rest/fc-networks/0b20f7fc-370d-4163-b8a6-dc06442f6657’]

These URI need to be placed in a json payload to send to the appliance.

How would i use args and *kwargs in this scenario.

Mark on June 14, 2020

Amazing!

mahlenius on July 16, 2020

THanks, now I understand these C-like symbols I have seen in argument lists of other code.

mortenelund on July 20, 2020

I needed an update on this and I have not seen any better! Thanks!

Agil C on Aug. 1, 2020

Thanks, very useful..!

Become a Member to join the conversation.