2.6.1 Lists
Python Programming
In Python, a list is a versatile data structure that can hold a collection of items. You can create, access, and modify lists easily.
2.6.1.1 Creating, Accessing, and Modifying Lists
A list is created by placing items inside square brackets [ ], separated by commas. Lists can contain items of different types, such as numbers, strings, or even other lists.
Example: Create a list of your favorite fruits.
python
fruits = ["Mango", "Apple", "Banana"]
print(fruits)
# Output: [’Mango’ ’Apple ’ ’Banana ’ ]Explanation: This code creates a list named 'fruits' containing three elements and then prints the list.