Python – something about function arguments

We have talked about briefly how to read in arguments from the command line using argparse from this post, however, do you know there is really a lot that you might not know about defining a function in Python. How to read optional argument, how to read in positional argument and also how the scope/namespace works. Those are all really interesting questions and you can check out this python documentation – Controlflow.

pythonargumentsThe example above show that an argument start with one start will read in the arguments sequentially and it doesn’t have to use the keyword args even if most people use *args all the time.

Second, **kwargs is short keyword arguments. As you can see, it will parse the function input as a dictionary and store the keyword along with its corresponding values in a dictionary.

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s