Created
December 20, 2018 11:01
-
-
Save bergpb/d4e6dd939ceccb8072c7cb1e0e547c9f to your computer and use it in GitHub Desktop.
Python args and kwargs usage.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| show_name_and_age(*args, **kwargs): | |
| for name in args: | |
| print('My name is: {}'.format(name)) | |
| for name in kwargs.keys(): | |
| print('{} has {} years old.'.format(name, kwargs[name])) | |
| show_name_and_age('Josh', 'Hannah', Josh=19, Hannah=26) | |
| # out | |
| # My name is: Josh | |
| # My name is: Hannah | |
| # Hannah has 26 years old. | |
| # Josh has 19 years old. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment