List Comprehensions in Python

Listen-MethodenTuples

List comprehensions are a powerful and concise way to create new lists in Python. They combine loops and conditions into a single, readable line.

Instead of writing a multi-line for loop to build a list, you can often do it in one elegant expression. This makes code shorter, faster, and easier to understand.

List comprehensions are very common in Python code – once you learn them, you'll use them everywhere!

Basic List Comprehension

The syntax is: [expression for item in iterable]

Example: Create a list of squares.

With Condition – Filtering

Add if condition to include only certain items: [expression for item in iterable if condition]

Transforming with Expression

The expression at the beginning can be any calculation or function call.

Nested List Comprehensions

For multi-dimensional data, you can nest comprehensions.

When to Use List Comprehensions

Use them for simple transformations and filtering. For complex logic with multiple statements, regular loops are clearer.

Quick Quiz

Wir haben die Materialien überprüft, dennoch können Fehler vorkommen. Der Inhalt dient ausschließlich Bildungszwecken, daher verwende ihn auf eigene Verantwortung und überprüfe ihn bei Bedarf mit anderen Quellen.

✨ Frag Lara — deine KI-Lernpartnerin

Entsperre personalisierte Lernunterstützung. Lara kann Lektionen erklären, Themen zusammenfassen und deine Lernfragen beantworten — verfügbar ab dem Go-Tarif.


Lara hilft dir, schneller zu lernen — exklusiv für ReadyTools Go-, Plus- und Max-Mitglieder.

Verfolge deinen Fortschritt 🚀

Lerne einfacher, indem du deinen Fortschritt kostenlos verfolgst.