GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-106318: Add example for str.format() (#137018) · StanFromIreland/cpython@6a5f5fd

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Doc/library
    • stdtypes.rst
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Doc/library/stdtypes.rst‎

Copy file name to clipboardExpand all lines: Doc/library/stdtypes.rst
+7-1Lines changed: 7 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1994,10 +1994,16 @@ expression support in the :mod:`re` module).
19941994
``{}``. Each replacement field contains either the numeric index of a
19951995
positional argument, or the name of a keyword argument. Returns a copy of
19961996
the string where each replacement field is replaced with the string value of
1997-
the corresponding argument.
1997+
the corresponding argument. For example:
1998+
1999+
.. doctest::
19982000

19992001
>>> "The sum of 1 + 2 is {0}".format(1+2)
20002002
'The sum of 1 + 2 is 3'
2003+
>>> "The sum of {a} + {b} is {answer}".format(answer=1+2, a=1, b=2)
2004+
'The sum of 1 + 2 is 3'
2005+
>>> "{1} expects the {0} Inquisition!".format("Spanish", "Nobody")
2006+
'Nobody expects the Spanish Inquisition!'
20012007

20022008
See :ref:`formatstrings` for a description of the various formatting options
20032009
that can be specified in format strings.

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.