How to Make a Dictionary in Python?

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

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

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

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

Add items to an existing dictionary: `my_dict[“city”] = “New York”`

Create a dictionary from a list of tuples: `my_dict = dict([(“name”, “Alice”), (“age”, 25)])`

Create a dictionary using `zip()`: `my_dict = dict(zip([“name”, “age”], [“Alice”, 25]))`

Suggested for You

Trending Today