← Python tutorial

Python

Lists

A list holds an ordered collection of values: fruits = ["apple", "banana"]. Access items by zero-based index (fruits[0]), and add with .append().

Example: a list comprehension

numbers = [1, 2, 3, 4, 5]
doubled = [n * 2 for n in numbers]

print(doubled)
[2, 4, 6, 8, 10]

[n * 2 for n in numbers] is a list comprehension, a compact way to build a new list by transforming every item in an existing one. It's equivalent to writing a full for loop that appends to an empty list one item at a time, just shorter and, once the syntax is familiar, more readable at a glance. It's a genuinely idiomatic Python pattern worth learning early, since you'll see it constantly in real Python code.

Example
numbers = [1, 2, 3, 4, 5]
doubled = [n * 2 for n in numbers]

print(doubled)
Output
[2, 4, 6, 8, 10]
Ready to go further?

These free tutorials are a preview, our Backend Development cohort covers it in depth, with a real project and a cohort alongside you. Active

Enroll in Backend Development
Don't miss out

Ready to build something real?

Create a free account to enroll in a track, and get notified the moment a cohort opens.

Create free account