Lesson 14 of 55 · Python
List Comprehensions
Duration: 20 minutes
Lesson 14 of 55 · Python
Duration: 20 minutes
python\n# Squares of numbers 0‑9\nsquares = [x * x for x in range(10)]\nprint(squares)\n\n# Filtering even numbers from 0‑19\nevens = [x for x in range(20) if x % 2 == 0]\nprint(evens)\n\n\nThe general syntax is [expression for item in iterable if condition].\n