How to Create Dictionary in Python?

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

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

Create an empty dictionary: `{}`

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

Use a list of key-value tuples: `dict([(“name”, “Alice”), (“age”, 25)])`

Use dictionary comprehension: `{x: x * x for x in range(5)}`

Use `zip()` with `dict()`: `dict(zip([“name”, “age”], [“Alice”, 25]))`

Suggested for You

Trending Today