/  Format() method in Python Built in Function

Format() method in Python Built in Function

 

Format method in built in function formats a specified value which is controlled format specifier.

 

Syntax:

format(value[, format_spec])

 

Parameter

Format method has two parameters.

  1. Value: this is the parameter which need to be formatted
  2. Format spec:this is the specification on how the value should be formatted.

 

Example-1:

x = format(0.5, '%')
print(x)

 

Output:

 

Using percentage in format method

 

Example-2:

 

Using integer in format method

print(format(123, "d"))

 

Output:

 

Example-3:

 

Using float in format method

print(format(123.4567898, "f"))

 

Output:

Format () method in Python Built in Function

 

 Example-4:

 

Using binary in format method

print(format(12, "b"))

 

Output:

Format () method in Python Built in Function

 

 Example-5

print(format(1234, "*>+7,d"))

 

Output:

Format () method in Python Built in Function