Skip to content

List

In one line

A list is an ordered, mutable collection of items in Python, written as [1, 2, 3].

In simple words

A Python list is an ordered collection that can hold any mix of types — numbers, strings, even other lists. Lists are mutable, meaning you can add, remove, or change elements after creating them. They are written with square brackets: [1, 2, 3].

Lists are the go-to data structure in Python for sequences of items. You can iterate over them with a for loop, access elements by index (my_list[0]), slice them (my_list[1:3]), and use methods like append(), remove(), and sort().

Python lists are similar to JavaScript arrays, but they are more flexible with types — a single list can hold integers, strings, and objects together. They are implemented as dynamic arrays under the hood, so appending is fast but inserting at the front is slow.

Example

python
fruits = ["apple", "banana", "cherry"]

print(fruits[0])       # "apple"
print(len(fruits))    # 3

fruits.append("date")
print(fruits)         # ["apple", "banana", "cherry", "date"]

for fruit in fruits:
    print(fruit)

Lists support indexing, len(), append(), and iteration with a for loop.

Common confusions

  • Confused with: array

    The difference: In Python, the built-in sequence type is called a list and can hold mixed types. Other languages (JavaScript, C) call the same concept an array. Python's array module exists but is for homogeneous numeric data and is rarely used.

  • Confused with: tuple

    The difference: A list is mutable — you can change, add, and remove elements. A tuple is immutable — once created, it cannot be changed. Use lists for changing sequences, tuples for fixed records.

Related terms

Related Resources

Related Lessons

Related Projects

Learn the fundamentals

Deepen your understanding with structured lessons on this topic.

View lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary