Working with Lists in Python
Learn how to create, index, slice, and manipulate lists in Python with this step-by-step tutorial.
Introduction to Lists
Lists are a fundamental data structure in Python, used to store multiple values in a single variable.
Creating Lists
You can create a list by placing values inside square brackets [] and separating them with commas.
fruits = ['apple', 'banana', 'cherry']
print(fruits)
Indexing Lists
You can access a specific element in a list by its index, which starts from 0.
fruits = ['apple', 'banana', 'cherry']
print(fruits[0])
Slicing Lists
You can extract a subset of elements from a list using slicing.
fruits = ['apple', 'banana', 'cherry', 'date', 'elderberry']
print(fruits[1:3])
Manipulating Lists
You can add, remove, and modify elements in a list using various methods.
fruits = ['apple', 'banana', 'cherry']
fruits.append('date')
print(fruits)
Ready for more? These paid resources pick up where this lesson leaves off.
Project-based python video courses — the perfect paid next step after these free lessons.
Browse on Udemy →Hand-picked python books to master the fundamentals offline.
See on Amazon →Some links on this page are affiliate links: we may earn a commission at no extra cost to you. We only recommend tools we believe are genuinely useful.