How to Use format() Function in PythonPython Basics


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.

© 2024 Cheerlearn.com, all rights reserved. Privacy Policy | Contact Us