Python_Data_Structures
Python_Data_Structures
Lists
A list in Python is a collection of items that is ordered and mutable. Lists allow duplicate
elements and can store items of different data types.
# Example of a list
fruits = ["apple", "banana", "cherry"]
print(fruits[0]) # Output: apple
# Removing an item
fruits.remove("banana")
Tuples
A tuple is similar to a list but is immutable. Once created, its values cannot be changed.
Tuples are useful for representing fixed collections of items.
# Example of a tuple
coordinates = (10, 20, 30)
print(coordinates[1]) # Output: 20
# Example of a dictionary
person = {"name": "John", "age": 30, "city": "New York"}
print(person["name"]) # Output: John