# A Python program returning multiple values from a method using dictionary
# Function is define that returns a dictionary
def fun():
d = dict();
d['str'] = "Demo"
d['x'] = 20
return d
# Driver code to test above method
d = fun()
print(d)
Output:
{'x': 20, 'str': 'Demo'}
Explanation:
A Dictionary consist of Key Value pairs with syntax Key:Syntax enclosed within {}. The value within Dictionary is accessed via key. Dictionary are updatable i.e values can be edited or deleted via keys. In above program a dictionay is defined via dict() within which key str and x is created with their values. The dictionary is then returned from function fun() and values are then printed. The values can also be printed via keys i.e
# Driver code to test above method
d = fun()
print(d['str'])
print(d['x'])
Output::
Demo
20
0 Comment(s)