format()

The built-in function that turns a value into a string using a format specifier, as in format(3.14159, ".2f").

In more detail

It uses the same specifiers as a replacement field, so format(x, ".3f") matches "{:.3f}".format(x). It returns a string for display; to change the number itself use round.

Example

format(2/3, ".3f")   # "0.667"

Related terms

Taught in

References