Next Tutorial >> Classes & Objects in Python
In this tutorial, we will be learning to pass a dictionary to the Python function as a parameter.
Pre-requisite : Functions in Python
We can pass a dictionary to a function in the same way as we pass other objects like list, tuple, string etc.
def fun(dictionary):
for k, v in dictionary.items():
print('key : {}, Value : {}'.format(k, v))
teams = {'India': 1, 'Australia': 2, 'England': 3, 'Newzealand': 4, 'South Africa': 5}
fun(teams) # calling a function fun, passing dictionary as an argument
O/P
key : India, Value : 1
key : Australia, Value : 2
key : England, Value : 3
key : Newzealand, Value : 4
key : South Africa, Value : 5
That’s all here.
Next Tutorial >> Classes & Objects in Python
