The format function in Python provides a formatted version of the specified value.
Python format Function Syntax
It has the following syntax:
Example
format(value, format)
Parameters
- value: It is the value that needs to be formatted.
- format: It is the specification on how the value should be formatted.
Return
It provides a structured display of the specified value.
Python format Function Example
The following example demonstrates various formatting techniques using the format function in Python.
Example
# d, f and b are a type
# integer
print(format(123, "d"))
# float arguments
print(format(123.4567898, "f"))
# binary format
print(format(12, "b"))
Output:
Output
123
123.456790
1100
Clarification: The preceding example yields a structured depiction of the values.