CodingNic

Generators, Iterators, and Decorators

Module Overview

Generators, Iterators, and Decorators 5 min read

Module Overview

Generators, Iterators, and Decorators

This module covers four related but distinct tools: generators (functions that produce values lazily, one at a time), the more general concept of iterators, decorators (functions that wrap other functions to add behavior), and two smaller but handy topics: lambdas and the datetime module.

Why This Matters

Generators let you work with huge or even infinite sequences without computing everything upfront. Decorators are everywhere in real Python code. You’ve already used @property, @classmethod, and @staticmethod in the OOP module; now you’ll see how a decorator like that actually works under the hood, and build your own.

What You’ll Learn

  • Generator functions, yield, and the next() function
  • Iterators, the iter() function, and enumerate
  • How to write your own decorators, and why functools.wraps matters
  • Lambdas, and basic date/time handling with the datetime module

Outcome

By the end of this module, you’ll be able to write lazy, memory-efficient generators and wrap existing functions with your own custom decorators.

Let’s get started.