StudyToCert

All certifications / PCEP / Lessons

PCEP – Certified Entry-Level Python Programmer PCEP-30-02 · Domain 3: Data collections: tuples, dictionaries, lists and strings

Iterating through lists, in and not in, list comprehensions with conditions

▶ Watch the overview video

Last reviewed September 30, 2026 · Leer en español

The most common thing to do with a list is to process each item in turn. A for loop over the list gives you each element directly, one per iteration: for price in prices: total += price. The loop variable is simply bound to the next element each time; it is not a position. If you also need positions, loop over range(len(prices)) or use enumerate(prices), which yields pairs of index and value. When you need to change items in place, use the index form (prices[i] = prices[i] * 2), because assigning to the loop variable only rebinds that name and does not modify the list.

Free account

Keep reading for free

Create a free StudyToCert account to read the rest of this lesson: 7 more sections, 6 key terms, a real-world example, an exam tip and self-check questions. Every lesson, lab and practice test is free with an account.

Sign up free Log in

Study PCEP for free
A week-by-week plan with every lesson, quizzes, checkpoint tests, a practice exam and hands-on labs.
Open the PCEP study plan