Courseiva

PCEP Computer Programming and Python Fundamentals Practice Question

A programmer wants to iterate over a list and also access the index. Which built-in function should they use?

⚠ Common exam trap

The PCEP exam often tests the distinction between `enumerate()` and `range(len())`, where candidates mistakenly think `range()` alone provides index access, but it only generates numbers and requires explicit indexing into the list.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

enumerate()

The `enumerate()` function is the correct choice because it returns an iterator that yields pairs of (index, element) for each item in an iterable, allowing direct access to both the index and the value during iteration without manually managing a counter.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    zip()

    Why it's wrong here

    zip() pairs elements from multiple iterables positionally, producing tuples of values but no index counter. It is tempting because it iterates cleanly, and it would be correct when combining two or more parallel lists, such as pairing names with scores.

  • ✗

    map()

    Why it's wrong here

    map() applies a function across an iterable and returns transformed values, discarding positional information entirely. It is tempting because it iterates implicitly, and it would be correct for element-wise transformation, such as converting every string in a list to uppercase.

  • ✓

    enumerate()

    Why this is correct

    enumerate() yields pairs of index and value while iterating, so the loop unpacks both without manual counter management. It satisfies the requirement to access the index directly, unlike range() combined with indexing or zip(), which needs a separate sequence.

  • ✗

    range()

    Why it's wrong here

    range() yields integers only, so the element itself is unavailable without a separate list lookup by subscript. It is tempting because range(len(list)) is the classic manual idiom, and it would be correct when only positional numbers are needed, such as generating numeric sequences.

About these practice questions

This PCEP question is part of Courseiva's 482-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This PCEP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCEP exam.