BeginnerCoder
beginner#python#lists#data structures

Working with Lists in Python

This article was AI-drafted and has not been reviewed yet. Spotted a mistake? Tell us.

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)
Keep going with python

Ready for more? Optional paid resources that pick up where this lesson leaves off.

Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.