Python dict() built-in function

From the Python 3 documentation

Create a new dictionary. The `dict` object is the dictionary class.

The dict() constructor in Python is a versatile way to create dictionaries.

You can create an empty dictionary, or create a dictionary from keyword arguments or from an iterable of key-value pairs.

Examples

Creating an empty dictionary:

my_dict = dict()
print(my_dict)  # Output: {}

Creating a dictionary with keyword arguments:

# Using keyword arguments
my_dict = dict(name="John", age=30)
print(my_dict)  # Output: {'name': 'John', 'age': 30}

Creating a dictionary from an iterable:

my_list = [('name', 'Jane'), ('age', 25)]
my_dict = dict(my_list)
print(my_dict)  # Output: {'name': 'Jane', 'age': 25}

Creating an empty dictionary:

>>> a = dict()
>>> type(a)
# <class 'dict'>

Subscribe to pythoncheatsheet.org

Join 16,702+ Python developers in a two times a month and bullshit free publication , full of interesting, relevant links.