How to use format() function in Python

The format() function is a built-in function in Python that returns a formatted representation of a value controlled by a format specifier. This method is created to handle complex string formatting more efficiently.

Returns: It returns the formatted representation of the value controlled by the format specifier.

Syntax

format(valuee[, format_specifier])

From the above syntax, we can say that the format() function takes two parameters, value (the value that needs to be formatted) and format_specifier (the specification of how the value needs to be formatted).

Code

print(format(255.4226,"f")) #float argument
print(format(365,"d")) #integer
print(format(45,"b")) #binary argument