Courseiva
Computer Programming and Python FundamentalshardMultiple ChoiceObjective-mapped

PCEP Computer Programming and Python Fundamentals Practice Question

Which of the following is the most efficient (Pythonic) way to create a list of squares for numbers 0 through 9?

⚠ Common exam trap

The PCEP exam often tests the distinction between list comprehensions and generator expressions, trapping candidates who confuse the lazy evaluation of generators with the eager construction of lists.

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

squares = [i*i for i in range(10)]

Uses a list comprehension, which is the most Pythonic and efficient way to create a list because it combines iteration and list construction in a single, readable expression. It avoids the overhead of repeated method calls (like `append`) and is faster than `map` with a lambda due to reduced function call overhead.

Answer analysis

Option-by-option breakdown

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

  • squares = [i*i for i in range(10)]

    Why this is correct

    List comprehension is preferred.

  • squares = []; for i in range(10): squares.append(i*i)

    Why it's wrong here

    Correct but not the most efficient.

  • squares = list(map(lambda x: x*x, range(10)))

    Why it's wrong here

    Works but less Pythonic.

  • squares = (i*i for i in range(10))

    Why it's wrong here

    This is a generator, not a list.

Quick reference

Cloud Service Model Comparison

ModelYou ManageProvider ManagesExamples
IaaSOS, runtime, apps, dataHardware, hypervisor, networkingEC2, Azure VMs, GCP Compute Engine
PaaSApps and dataOS, runtime, middleware, hardwareElastic Beanstalk, Azure App Service
SaaSData and settings onlyEverything elseMicrosoft 365, Salesforce, Workday
FaaS / ServerlessFunction code onlyInfra, scaling, runtimeLambda, Azure Functions, Cloud Run
CaaSContainers and appsKubernetes, OS, hardwareEKS, AKS, GKE

About these practice questions

This PCEP question is part of Courseiva's 498-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.