Maurice
asked

Expert
Kelish Rai answered
In Python, lists and dictionaries are two important data types that allow you to store and organize data in different ways.
A list is an ordered collection of items where each item is identified by an index (starting from 0). Lists are created using square brackets []. For example,
fruits = ["apple", "banana", "cherry"]
print(fruits[0]) # Output: appleA dictionary is a collection of key-value pairs where each value is accessed by its unique key, not by index. Dictionaries are created using curly braces {}. For example,
person = {"name": "Alice", "age": 25}
print(person["name"]) # Output: AliceBoth are very flexible and widely used for different purposes in Python programming.
Python
This question was asked as part of the DSA with Python course.
Our Experts
Sudip BhandariHead of Growth/Marketing
Apekchhya ShresthaSenior Product Manager
Kelish RaiTechnical Content Writer
Abhilekh GautamSystem Engineer
Palistha SinghTechnical Content Writer
Sarthak BaralSenior Content Editor
Saujanya Poudel
Abhay Jajodia
Nisha SharmaTechnical Content Writer
Udayan ShakyaTechnical Content Writer