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
| Model | You Manage | Provider Manages | Examples |
|---|---|---|---|
| IaaS | OS, runtime, apps, data | Hardware, hypervisor, networking | EC2, Azure VMs, GCP Compute Engine |
| PaaS | Apps and data | OS, runtime, middleware, hardware | Elastic Beanstalk, Azure App Service |
| SaaS | Data and settings only | Everything else | Microsoft 365, Salesforce, Workday |
| FaaS / Serverless | Function code only | Infra, scaling, runtime | Lambda, Azure Functions, Cloud Run |
| CaaS | Containers and apps | Kubernetes, OS, hardware | EKS, AKS, GKE |
Go deeper
Related to this question
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 →
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.