Built-in modules for strings

The Python standard library contains a number of built-in modules that you can use to manage strings:

Module

Description

string

compares with constants such as string.digits or string.whitespace

re

searches and replaces text with regular expressions

struct

interprets bytes as packed binary data

difflib

helps to calculate deltas, find differences between strings or sequences and create patches and diff files

textwrap

wraps and fills text, formats text with line breaks or spaces