Python format() Function

The python format() function returns a formatted representation of the given value.

Python format() Function Syntax

It has the following syntax:

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 returns a formatted representation of the given value.

Python format() Function Example

The below example shows a number of formatting with format() function in Python.

# 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:

123
123.456790
1100

Explanation: The above example returns a formatted representation of the values.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *