Python/Old string formatting
[i]Learn· Input and Output

Old string formatting

The % operator (modulo) can also be used for string formatting. Given format % values (where format is a string), % conversion specifications in format are replaced with zero or more elements of values. This operation is commonly known as string interpolation. For example:

>>> import math
>>> print('The value of pi is approximately %5.3f.' % math.pi)
The value of pi is approximately 3.142.

More information can be found in the printf-style String Formatting section.

Source: Input and Output by Python Software Foundation, licensed under PSF-2.0. Retrieved 2026-11-18. Changes: Extracted section 7.1.4 from The Python Tutorial (Python 3.14), https://docs.python.org/3.14/tutorial/inputoutput.html; removed section numbers, permalinks and site navigation; code blocks kept as shown; runnable examples: prompts and output lines removed.