Google News
logo
Python Program to Using the dict() constructor to create a Dictionary
In the following example of Python program that uses the `dict()` constructor to create a dictionary :
Program :
# create a dictionary using dict() constructor
my_dict = dict(name='John', age=32, city='New York')

# print the dictionary
print(my_dict)
Output :
{'name': 'John', 'age': 32, 'city': 'New York'}
In the above program, we create a dictionary called `my_dict` using the `dict()` constructor. We pass in the key-value pairs separated by commas and `dict()` method converts them into a dictionary object. We then print the contents of the dictionary using the `print()` function.