Skip to content
Built-in Functions

format()

Format a value as text using a format specification.

format(value, format_spec="")

format() turns a value into a string with a chosen display style. For example, .2f displays a number with two decimal places.

Parameters

NameDescription
valueThe value to format.
format_specOptional formatting instructions as a string.

Returns

A formatted string.

Try it

Run it and change it
price = 7.5
print(format(price, ".2f"))

Related entries