CertGrid CertGrid
Concepts·Certified Entry-Level Python Programmer

Python Generators and yield

PCEP names generators in passing under objective 4.1 and asks little about them; PCAP's comprehension and closure material assumes you know what a lazy sequence is. This guide fills that gap. A generator is a function containing yield: calling it runs none of the body, and each next() runs it as far as the next yield and then freezes it there. Seeing that interleaving is the only way it becomes obvious.

Functions and Scope Guide 22 of 26 Intermediate

yield has been in Python since 2.2 and generator expressions since 2.4. Nothing here is version-sensitive. yield from and send() exist and are examined by neither exam.

One machine, and any shell with Python 3 will do - these exams test the language, not a distribution.
Server NameIP AddressOSRolesCPURAMHDD
RUNNER01192.168.0.27Ubuntu 26.04 LTSPython 3.14.4 - the only machine this path needs2 Core4 GB50 GB

This guide includes

Use this for the generator material PCEP names in passing and PCAP tests properly. This matters because a generator produces nothing until asked and can be walked only once - so whatever consumes it second gets an empty sequence.

Before you start

  1. yield instead of return

  2. Running off the end

  3. A generator works anywhere an iterable does

  4. A generator can only be walked once

  5. How little work happens before you ask

  6. The generator expression

  7. What the exams do with generators

Official sources