# The format method is a built-in Python string formatting method.
The basic syntax is: str.format(), which enhances the string formatting function.
The basic syntax is to use {} and : to replace the previous %.
The format function can receive multiple parameters, and the positions do not need to be in order.
Specific examples are as follows:
>>> print("{:.0f}".format(3.1415926)) 3 >>> print("{:.2f}".format(3.1415926)) 3.14 >>> print("{:.3f}".format(3.1415926)) 3.142
Recommended tutorial: python tutorial
The above is the detailed content of Python uses the format method to retain three decimal places. For more information, please follow other related articles on the PHP Chinese website!