The difflib module of Python

Overview:

The Python difflib module provides classes and functions to compare sequences including text strings. The differences can be listed using either in contextual difference mode or in full difference mode.

The SequenceMatcher class compares any sequence e.g., list, tuple - whose items are hashable. The SequenceMatcher class can also be used to find differences between two text strings.

The HtmlDiff class compares two texts and returns the results as HTML containing the differences in texts. The HTML can be written to a file by opening a file and calling the write() method. The HTML output has legends specifying which color denotes the added, changed and deleted texts.


Copyright 2026 © pythontic.com