Python format() FunctionPython Functions

Difficulty Level:
Difficulty Level:

The format() method returns a formatted expression of the given value controlled by the format specifier.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

print(dir())

Output:

['__annotations__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__']

Syntax

format(value[, format_spec])

Parameters

Name Description
value The value which needs to be formatted.
format_spec The specification of how the value should be formatted.

Return Value

It returns a formatted expression of a given value.

Advertisement

© 2021 Pythonexample.org, all rights reserved. Privacy Policy | Contact Us