Lists and Related Operations
A list is an ordered, changeable collection of items in Python. Lists are one of the most commonly used data structures, especially for holding rows of data, results, or any group of related values.
Creating a List
scores = [72, 85, 90, 66]
names = ["Aditi", "Rahul", "Meera"]
Indexing and Slicing
print(scores[0])
print(scores[-1])
print(scores[1:3])
Common List Operations
scores.append(95)
scores.insert(0, 60)
scores.remove(66)
scores.sort()
print(len(scores))
List Comprehension
List comprehensions offer a concise way to build new lists from existing ones.
squares = [n * n for n in range(5)]
print(squares)
Lists map closely to columns of data you'll work with later using Pandas, so getting comfortable with indexing, slicing, and looping over lists pays off directly in data science tasks.
Coming Up
Next, you'll look at tuples, a data structure similar to lists but with one key difference: once created, a tuple cannot be changed.