A dictionary in Python is a collection of data which is unordered and mutable. Unlike, numeric indices used by lists, a dictionary uses the key as an index for a specific value. It can be used to store unrelated data types but data that is related as a real-world entity. The keys themselves are employed for using a specific value.
Refer to the below article to get the idea about Python Dictionary.
Passing Dictionary as an argument
In Python, everything is an object, so the dictionary can be passed as an argument to a function like other variables are passed.
Example:
# Python program to demonstrate # passing dictionary as argument # A function that takes dictionary # as an argument def func(d): for key in d: print("key:", key, "Value:", d[key]) # Driver's code D = {'a':1, 'b':2, 'c':3} func(D) |
Output:
key: b Value: 2 key: a Value: 1 key: c Value: 3
Passing Dictionary as kwargs
“kwargs” stands for keyword arguments. It is used for passing advanced data objects like dictionaries to a function because in such functions one doesn’t have a clue about the number of arguments, hence data passed is be dealt properly by adding “**” to the passing type.
Example 1:
# Python program to demonstrate # passing dictionary as kwargs def display(**name): print (name["fname"]+" "+name["mname"]+" "+name["lname"]) def main(): # passing dictionary key-value # pair as arguments display(fname ="John", mname ="F.", lname ="Kennedy") # Driver's code main() |
Output:
John F. Kennedy
Example 2:
# Python program to demonstrate # passing dictionary as kwargs def display(x = 0, y = 0, **name): print (name["fname"]+" "+name["mname"]+" "+name["lname"]) print ("x =", x) print ("y =", y) def main(): # passing dictionary key-value # pair with other arguments display(2, fname ="John", mname ="F.", lname ="Kennedy") # Driver's code main() |
Output:
John F. Kennedy x = 2 y = 0
Recommended Posts:
- Python | Passing dictionary as keyword arguments
- Python | Convert flattened dictionary into nested dictionary
- Python | Convert nested dictionary into flattened dictionary
- Python | Convert string dictionary to dictionary
- Regular Dictionary vs Ordered Dictionary in Python
- Python - Update dictionary with other dictionary
- Python - Filter dictionary values in heterogenous dictionary
- Python - Replace dictionary value from other dictionary
- Python - Append Dictionary Keys and Values ( In order ) in dictionary
- Packing and Unpacking Arguments in Python
- Python | Set 4 (Dictionary, Keywords in Python)
- Building a terminal based online dictionary with Python and bash
- Generate a graph using Dictionary in Python
- Dictionary Methods in Python | Set 1 (cmp(), len(), items()...)
- Dictionary Methods in Python | Set 2 (update(), has_key(), fromkeys()...)
- Output of Python programs | Set 9 (Dictionary)
- Python | Extract key-value of dictionary in variables
- Scraping And Finding Ordered Words In A Dictionary using Python
- Python Dictionary Comprehension
- Print anagrams together in Python using List and Dictionary
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

