Python format() Function

The format method conerts a value to a string using the specified format. For example, ".2f" means, format the value to two numbers past the decimal point.

Syntax

Python
format(object, spec)

Parameters

ParameterDescription
object Required. The object to be converted to a string
spec Required. The format specification.

Example

Python
price = 49
formattedPrice = format(price, '.2f')
print(formattedPrice)

Output

49.00