How can dictionaries be created in Python?

In Python, you can use curly braces {} to create a dictionary. For example:

my_dict = {'name': 'Alice', 'age': 30, 'city': 'New York'}

One option is to use the dict() function to create a dictionary. For example:

my_dict = dict(name='Alice', age=30, city='New York')

Additionally, you can also create a dictionary using dictionary comprehension. For example:

my_dict = {i: i**2 for i in range(5)}
Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds