Difflib
The difflib module compares sequences and produces human-readable diffs. It is used for text comparison, testing, and version control tools. The guide walks through Comparing Text. `import difflib`. `difflib.unified_diff(a_lines, b_lines)` — unified diff format. `difflib.context_diff` — context diff. `difflib.Differ` — line-by-line comparison. HTML diff: `difflib.HtmlDiff().make_file(a_lines, b_lines)`. Sequence matcher: `difflib.SequenceMatcher(None, a, b).ratio()` — similarity ratio (0-1). The guide is organized into 1 sections that build on each other, each pairing a prose explanation with runnable code. Browse the individual functions covered by this guide in the Difflib Module category. Key APIs covered include difflib.SequenceMatcher(), difflib.get_close_matches(), difflib.unified_diff(), difflib.context_diff(), difflib.ndiff(), difflib.HtmlDiff(). Related guides: builtins, string, list, dict, os. This is one of 48 Python guides on Python Reference — see the full list on the guides page. Practice what you learn in the Python playground, and look up any unfamiliar term in the Python glossary.