How to Create a Dictionary in Python?

Use curly braces with key-value pairs: `my_dict = {“name”: “Alice”, “age”: 25}`

Use the `dict()` constructor with keyword arguments: `my_dict = dict(name=”Alice”, age=25)`

Use the `dict()` constructor with a list of tuples: `my_dict = dict([(“name”, “Alice”), (“age”, 25)])`

Use `zip()` with `dict()` to create a dictionary from two sequences: `my_dict = dict(zip([“name”, “age”], [“Alice”, 25]))`

Create an empty dictionary with curly braces: `my_dict = {}`

Create an empty dictionary with `dict()`: `my_dict = dict()`

Suggested for You

Trending Today