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
| Name | Description |
|---|---|
| value | The value to format. |
| format_spec | Optional formatting instructions as a string. |
Returns
A formatted string.
Try it
Run it and change it
price = 7.5 print(format(price, ".2f"))