Python dict() FunctionPython dict() function is a constructor which creates a dictionary. Python dictionary provides three different constructors to a create dictionary.
SignatureParameterskwargs: It is a keyword argument. mapping: It is another dictionary. iterable: It is an iterable object in the form of a key-value pair(s). ReturnIt returns a dictionary. Let's see some examples of dict() function to understand it's functionality. Python dict() Function Example 1A simple example to create an empty or non-empty dictionary. Arguments of the dictionary are optional. Output: {} {'a': 1, 'b': 2} Python dict() Function Example 2Output: {'x': 5, 'z': 20, 'y': 10} {'x': 5, 'z': 20, 'y': 10} Python dict() Function Example 3Output: {1: 'One', 2: 'Two', 3: 'Three'} {'y': 'Y', 'x': 'X'} Next TopicPython Functions |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India