![]() |
VOOZH | about |
dict() function is a built-in constructor used to create dictionaries. A dictionary is a mutable collection of key-value pairs where each key is unique and insertion order is preserved.
{'One': '1', 'Two': '2'}
Explanation: Here, we create a dictionary using keyword arguments. The keys One and Two are assigned the values "1" and "2" respectively.
dict()
dict(mapping)
dict(iterable)
dict(**kwargs)
dict(mapping, **kwargs)
Parameter:
Return: The function returns a dictionary containing the specified key-value pairs.
Note: mapping and iterable cannot be passed together as two positional arguments
Example 1: Creating shallow copy of the dictionary
{'a': 10, 'b': 2, 'c': 3}
{'a': 10, 'b': 2, 'c': 3}
Explanation:
Example 2: Creating dictionary using iterables
{'a': 1, 'b': 2, 'c': 3, 'd': 4}
Explanation: