Function Details: format

Description


Returns value.__format__(format_spec).


Extended Description


The format() function returns a formatted representation of a value as controlled by format_spec. It internally calls the __format__() method of the value. This function is the basis of the advanced string formatting operations in Python, allowing for precise control over the output format of various data types.


Exceptions


  • ValueError: If an invalid format specification is provided

Read More about format from Python Documentation

Function Signature


format(value: Any, format_spec: str = '') -> str

Module: builtins

Parameters


value: The object to be formatted. format_spec: A string that specifies how the value should be formatted.


Parameter List


  • value: Any
  • format_spec: str

Return


Returns a formatted string representation of the value.


Return Type


str

Output

Explanation

This example shows basic number formatting with padding, precision, and thousands separator.