FlareStart
HomeNewsHow ToSources
FlareStart

Where developers start their day. All the tech news & tutorials that matter, in one place.

Quick Links

  • Home
  • News
  • Tutorials
  • Sources

Connect

© 2026 FlareStart. All rights reserved.

Back to articles
Python Generators Part 2: How They Actually Work (The Magic Revealed)
How-ToProgramming Languages

Python Generators Part 2: How They Actually Work (The Magic Revealed)

via Dev.to Pythonprashant chouksey22h ago

Understanding the pause button: frames, state, and bidirectional communication In Part 1, you learned: ✅ Generators produce values one at a time (lazy) ✅ The yield keyword pauses the function ✅ Generators use constant memory (112 bytes) ✅ Use for loops or next() to get values If you haven't reviewed Part 1 yet, please refer to it here . Now let's answer the big question: How does Python remember where it paused? The Big Question: Where is the State Saved? When a generator pauses at yield , it needs to remember: 📍 Where it was in the code (which line?) 🧮 All local variables (their current values) 📊 The call stack (in case there were nested function calls) Where does Python store all this? Answer: In a special object called a Generator Frame . What Happens When You Call a Generator Function Let's trace through this step-by-step: def counter ( start , end ): current = start while current < end : value = current ** 2 yield value current += 1 # Step 1: Call the function gen = counter ( 0 ,

Continue reading on Dev.to Python

Opens in a new tab

Read Full Article
1 views

Related Articles

Hey I'm new here. This is Masih Ahmed, officially Mr Ahmed, but you can call me just Masih. Whatever, As ya know I'm new here and I'm looking for friends to develop new things togerther. I'm a student, College 1st year and I'd like to share my learnings
How-To

Hey I'm new here. This is Masih Ahmed, officially Mr Ahmed, but you can call me just Masih. Whatever, As ya know I'm new here and I'm looking for friends to develop new things togerther. I'm a student, College 1st year and I'd like to share my learnings

Dev.to • 32m ago

️ Build Production-Ready Real-Time Voice Calls in Flutter with WebRTC
How-To

️ Build Production-Ready Real-Time Voice Calls in Flutter with WebRTC

Medium Programming • 59m ago

Why I Stopped Watching Endless Coding Tutorials (And What Happened Next)
How-To

Why I Stopped Watching Endless Coding Tutorials (And What Happened Next)

Medium Programming • 2h ago

How-To

How to Vulkan in 2026

Lobsters • 3h ago

Why Feeling Lost in Programming Is Completely Normal
How-To

Why Feeling Lost in Programming Is Completely Normal

Medium Programming • 4h ago

Discover More Articles