Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 30439b2

Browse files
committed
Document default fmtspec. Fix inaccurate note. Document exceptions.
1 parent 57e6eac commit 30439b2

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

Doc/library/functions.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -498,11 +498,14 @@ are always available. They are listed here in alphabetical order.
498498
of the *value* argument, however there is a standard formatting syntax that
499499
is used by most built-in types: :ref:`formatspec`.
500500

501-
.. note::
502-
503-
``format(value, format_spec)`` merely calls
504-
``value.__format__(format_spec)``.
505-
501+
The default *format_spec* is an empty string which usually gives the same
502+
effect as calling ``str(value)``.
503+
504+
A call to ``format(value, format_spec)`` is translated to
505+
``type(value).__format__(format_spec)`` which bypasses the instance
506+
dictionary when searching for the value's :meth:`__format__` method. A
507+
:exc:`TypeError` exception is raised if the method is not found or if either
508+
the *format_spec* or the return value are not strings.
506509

507510
.. function:: frozenset([iterable])
508511
:noindex:

0 commit comments

Comments
 (0)