How can we return a dictionary from a Python function?

PythonServer Side ProgrammingProgramming

There can be any number of ways we can return a dictionary from a python function. Consider the one given below.

Example

# This function returns a dictionary
def foo():
     d = dict();
     d['str'] = "Tutorialspoint"
     d['x']   = 50
     return d
print foo()

Output

{'x': 50, 'str': 'Tutorialspoint'}
raja
Published on 07-Dec-2017 16:40:07
Advertisements