USD ($)
$
United States Dollar
Euro Member Countries
India Rupee
د.إ
United Arab Emirates dirham
ر.س
Saudi Arabia Riyal

Lists and List Operations

Lesson 13/35 | Study Time: 45 Min

When working with data, you rarely deal with just one value at a time. You need to store, access, and manipulate collections of values and that is exactly what lists are for.

A list in Python is an ordered, changeable collection that can hold multiple items in a single variable. Lists are one of the most used data structures in Python, and mastering them is essential for data processing and AI work.

Creating a List

A list is defined using square brackets [], with items separated by commas. Lists can hold any data type — numbers, strings, booleans, or even a mix.

Accessing List Items — Indexing

Every item in a list has a position called an index, starting from 0. You can also use negative indexing to access items from the end.

Slicing a List

Slicing extracts a portion of a list using the format list[start:end]. The start index is included; the end index is not.

Modifying a List

Lists are mutable — meaning you can change their content after creation.

Common List Operations

Here are the most frequently used list methods:


Examples:

Useful Built-in Functions for Lists

Python has several built-in functions that work directly with lists:

Checking and Searching in a List

Iterating Over a List

Looping through a list is one of the most common operations in Python and AI data processing.

List Comprehension — A Cleaner Way to Build Lists

List comprehension is a concise, Pythonic way to create a new list from an existing one in a single line.


Sales Campaign

Sales Campaign

We have a sales campaign on our promoted courses and products. You can purchase 1 products at a discounted price up to 15% discount.