Python format() function
Python format() function
The format() function in Python formats a specified value into the given format. A ‘TypeErrorexception’ is raised if the method search reaches the object and the format_spec is non-empty, or if either the format_spec or the return value is not strings.
Syntax
format(value[, format_spec])
Parameter
value: This parameter represents a value of any format
format_spec :The format_specs parameter represents the format.
Return
This function returns the value in the specified format.
Example 1
#Python program explaining # the format() function val= 0.09 print("Number: ",val) #formating the specified value x = format(val, '%') print("After format() function: ",x)
Output
Number: 0.09 After format() function: 9.000000%