A list comprehension builds a new list from an existing one in a single line. It is shorter than a loop with an append, and once you read the pattern it is easy to follow.
The pattern
new_list = [expression for item in old_list if condition]
Examples
- Squares of numbers: [n * n for n in numbers]
- Only the even numbers: [n for n in numbers if n % 2 == 0]
- Upper-case names: [name.upper() for name in names]
When to use a normal loop
If the logic needs several steps or a clear name for each step, a plain loop is easier to read. Clear code matters more than a short line, especially for a team reviewing your work.
Practise on the basics first: variables, lists and loops. Our Python course includes daily exercises. Book a free demo class, and ask a counsellor for the current schedule.

Python Dictionaries Explained for Beginners - ScholarLogic
[…] Python basics: variables, lists and loops first, then list comprehensions. Book a free demo class and ask a counsellor about the Python […]