Last Updated: May 22, 2026
A pure function is a simple piece of code: it takes inputs, returns an output, and does nothing else. No printing, no file writes, no modifying its arguments, no reading hidden globals. Same input today, same output tomorrow. This lesson covers what purity means, the everyday Python patterns that break it, why pure code is easier to test and cache, and how to refactor a messy mix of math and I/O into a clean pure core wrapped by side effects at the edges.