Apart from the literal representation of dictionary, where we put comma-separated key:value pairs in curly brackets, we can create dictionary object with built-in dict() function.
Empty Dictionary
Using dict() function without any arguments creates an empty dictionary object. It is equivalent to putting nothing between curly brackets.
Example
It will produce the following output −
d1: {}
d2: {}
Dictionary from List of Tuples
The dict() function constructs a dictionary from a list or tuple of two-item tuples. First item in a tuple is treated as key, and the second as its value.
Example
It will produce the following output −
d1: {'a': 100, 'b': 200}
d2: {'a': 'one', 'b': 'two'}
Dictionary from Keyword Arguments
The dict() function can take any number of keyword arguments with name=value pairs. It returns a dictionary object with the name as key and associates it to the value.
Example
It will produce the following output −
d1: {'a': 100, 'b': 200}
d2: {'a': 'one', 'b': 'two'}
The End! should you have any inquiries, we encourage you to reach out to the Vercaa Support Center without hesitation.