Python for Data Analytics • Lesson 7

Lists

Learn how Python lists store multiple values, access items, modify data, add and remove elements, sort information and process collections of data.

Your progress0%

0 of 8 concepts completed

Complete the activity and related MCQ to unlock the next concept.

Concept 1LIST

What Is a List?

A list is a collection of values stored in a single variable. Lists use square brackets [ ], and can hold strings, numbers and other data types together.

Learn by Seeing

Square brackets hold many values

students = ["Aman", "Riya", "Rahul"]
prices = [500, 750, 1200, 900]

print(students[0])   # Aman

One variable, many values — the values keep their order.

A list holds multiple values. Edit the comma-separated items:

your list

0Aman1Riya2Rahul

Each item gets its own index starting at 0.

Interactive Activity

How many values are stored in prices = [500, 750, 1200, 900]?

Hint: Count the items inside the brackets.

Python Analyst Mindset

Lists are how Python holds your data

Before you can compute averages, find the top value, or clean a dataset, you need to hold a group of values somewhere. Lists are that container — the fundamental shape in which analysts store a column of data.

01

Store

Hold many values in one name.

02

Read

Index items with [i] or [-1].

03

Change

append, insert, remove, pop.

04

Analyze

len, sort, in.

Frequently Asked Questions

Lists — FAQs

append vs insert?

append always adds at the end. insert(i, x) adds at a specific position, shifting other items right.

remove vs pop?

remove(value) targets a value. pop() targets a position (default last) and returns the removed item.

Does sort() change the original list?

Yes. sort() sorts the list in place. Use sorted(list) if you want a new sorted copy and to leave the original untouched.

Why does the last index have to be len-1?

Indexing starts at 0, so a list of length N has valid indexes 0..N-1. Using list[-1] avoids needing to know the length.

Lesson Summary

What you learned

Create with [ ]

Lists hold multiple values in one variable.

Indexing

Start at 0; -1 refers to the last item.

Update items

Assign to a position to replace the value.

append / insert / remove / pop

Add or remove items by value or position.

len / sort / reverse

Count and order items.

Membership with in

Checks whether a value exists in a list.