loops

Iteration in code: for loops, while loops, ranges, and looping over lists, maps, and files, each shown with runnable examples and real output.

Python: Asyncio, async/await for I/O Concurrency

Here is a puzzle. You fire off ten network requests, each one takes about a second, and the whole thing finishes in one second flat. No extra threads. No extra Central Processing Unit (CPU) cores. Just one thread, running one task at a time. How? Welcome to Python asyncio, where a single thread juggles thousands of waiting operations by never sitting idle. “Concurrency is about structure, parallelism is about execution.” Rob Pike, Concurrency Is Not Parallelism Last Updated: July 2026 ... Read More

Python: Iterators and the Iterator Protocol

Ask Python to loop over a list, a file, or a dictionary, and it plays the same trick every time: it asks the object for a Python iterator, then pulls values one by one until StopIteration says stop. This post unpacks that protocol, __iter__ and __next__ included, and shows you how to build a custom iterator of your own. “Simple is better than complex. Complex is better than complicated.” Tim Peters, The Zen of Python (PEP 20) Last Updated: July ... Read More

Python: Recursion, Base Cases, Stack, Practical Examples

A function that calls itself sounds like a fast track to an infinite loop, yet Python recursion is one of the tidiest ways to walk a folder tree, sum a nested list, or compute a factorial. The secret is a stopping rule called the base case. This guide builds recursive functions step by step, watches the call stack grow and unwind, shows why a naive Fibonacci makes your laptop fan scream, and pins down when a plain loop wins instead. ... Read More