We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f7b3efc commit 8068d92Copy full SHA for 8068d92
fundamentals/python/src/kwargs.py
@@ -0,0 +1,13 @@
1
+# kwargs : Key Word Arguments
2
+# ** in a function declaration means collect all keyword arguments into a dictionary
3
+# named kwargs.
4
+# And for the callee
5
+def print_info(**kwargs):
6
+ for key, value in kwargs.items():
7
+ print(f"{key}: {value}")
8
+
9
+# Call with any number of keyword arguments
10
+print_info(name="Dan", age=50, city="Stockholm")
11
12
+dict = {"name":"Dan", "age":50, "city":"Stockholm"}
13
+print_info(**dict) # Unpack the dictionary into keyword arguments
0 commit comments