
Python
Learning Level
Lists store multiple items in a specific order, and you access them using their position (index).
A list is a collection of items enclosed in square brackets, separated by commas. Order matters!
# Empty list
empty_list = []
# List of numbers
numbers = [10, 20, 30, 40, 50]
# List of strings
colors = ["red", "green", "blue"]
# Mixed data types
mixed = [1, "hello", 3.14, True]Python uses zero-based indexingβthe first item is at position 0, not 1. You access items using square brackets with the index.
fruits = ["apple", "banana", "orange", "grape"]
print(fruits[0]) # apple (first item)
print(fruits[1]) # banana (second item)
print(fruits[3]) # grape (fourth item)
print(fruits[-1]) # grape (last item, negative index)
print(fruits[-2]) # orange (second from last)# Student's test scores in order
grades = [85, 92, 78, 88, 95]
# Access specific grades
first_test = grades[0] # 85
last_test = grades[-1] # 95
# Find average
average = sum(grades) / len(grades)
print(f"Average: {average}") # Average: 87.6fruits = ["apple", "banana", "orange", "grape"]
Index: 0 1 2 3
β β β β
List: apple banana orange grape
β β β β
Negative: -4 -3 -2 -1Ready to practice? Challenges | Quiz
Resources
Ojasa Mirai
Master AI-powered development skills through structured learning, real projects, and verified credentials. Whether you're upskilling your team or launching your career, we deliver the skills companies actually need.
Learn Deep β’ Build Real β’ Verify Skills β’ Launch Forward