Last active
November 7, 2021 13:31
-
-
Save Pierre-Sassoulas/6c32a7dbf940d6bcb8a771a68533b4f1 to your computer and use it in GitHub Desktop.
Python args/kwargs example
This file contains 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
def example(*args, **kwargs): | |
print("Args:", args, "Kwargs:", kwargs) | |
args = [1, 2] | |
kwargs = {"pos_x": 1, "pos_y": 2} | |
print("Standard call") | |
example(1, 2) | |
print("Keyword call") | |
example(pos_x=1, pos_y=2) | |
print("Args call") | |
example(*args) | |
print("Kwargs call") | |
example(**kwargs) | |
print("Strange call") | |
example(*kwargs) | |
print("Mixed call") | |
example("a", b=42, **kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment