Skip to content

Commit 62af722

Browse files
committed
Use doctest directives
1 parent e06ff6b commit 62af722

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Doc/library/stdtypes.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2491,7 +2491,7 @@ These expressions are evaluated at runtime, similarly to :meth:`str.format`,
24912491
and are converted into regular :class:`str` objects.
24922492
For example:
24932493

2494-
.. code-block:: pycon
2494+
.. doctest::
24952495

24962496
>>> who = 'nobody'
24972497
>>> nationality = 'Spanish'
@@ -2500,7 +2500,7 @@ For example:
25002500

25012501
It is also possible to use a multi line f-string:
25022502

2503-
.. code-block:: pycon
2503+
.. doctest::
25042504

25052505
>>> f'''This is a string
25062506
... on two lines'''
@@ -2509,31 +2509,31 @@ It is also possible to use a multi line f-string:
25092509
A single opening curly bracket, ``'{'``, marks a *replacement field* that
25102510
can contain any Python expression:
25112511

2512-
.. code-block:: pycon
2512+
.. doctest::
25132513

25142514
>>> nationality = 'Spanish'
25152515
>>> f'The {nationality} Inquisition!'
25162516
'The Spanish Inquisition!'
25172517

25182518
To include a literal ``{`` or ``}``, use a double bracket:
25192519

2520-
.. code-block:: pycon
2520+
.. doctest::
25212521

25222522
>>> x = 42
25232523
>>> f'{{x}} is {x}'
25242524
'{x} is 42'
25252525

25262526
Functions can also be used, and :ref:`format specifier <formatstrings>`:
25272527

2528-
.. code-block:: pycon
2528+
.. doctest::
25292529

25302530
>>> from math import sqrt
25312531
>>> f'√2 \N{ALMOST EQUAL TO} {sqrt(2):.5f}'
25322532
'√2 ≈ 1.41421'
25332533

25342534
Any non-string expression is converted using :func:`str`, by default:
25352535

2536-
.. code-block:: pycon
2536+
.. doctest::
25372537

25382538
>>> from fractions import Fraction
25392539
>>> f'{Fraction(1, 3)}'
@@ -2552,7 +2552,7 @@ Conversion Meaning
25522552

25532553
For example:
25542554

2555-
.. code-block:: pycon
2555+
.. doctest::
25562556

25572557
>>> from fractions import Fraction
25582558
>>> f'{Fraction(1, 3)!s}'
@@ -2569,7 +2569,7 @@ This preserves spaces within the brackets, and can be used with a converter.
25692569
By default, the debugging operator uses the :func:`repr` (``!r``) conversion.
25702570
For example:
25712571

2572-
.. code-block:: pycon
2572+
.. doctest::
25732573

25742574
>>> from fractions import Fraction
25752575
>>> calculation = Fraction(1, 3)
@@ -2588,7 +2588,7 @@ or the empty string if no format specifier is given.
25882588
The formatted result is then used as the final value for the replacement field.
25892589
For example:
25902590

2591-
.. code-block:: pycon
2591+
.. doctest::
25922592

25932593
>>> from fractions import Fraction
25942594
>>> f'{Fraction(1, 7):.6f}'

0 commit comments

Comments
 (0)