Skip to content

Commit 7513b9c

Browse files
committed
Fixed incorrect example in functions documentation
1 parent 0c1feeb commit 7513b9c

File tree

1 file changed

+36
-34
lines changed

1 file changed

+36
-34
lines changed

Doc/library/functions.rst

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -385,41 +385,43 @@ are always available. They are listed here in alphabetical order.
385385

386386
.. doctest::
387387

388-
>>> complex('+1.23')
389-
(1.23+0j)
390-
>>> complex('-4.5j')
391-
-4.5j
392-
>>> complex('-1.23+4.5j')
393-
(-1.23+4.5j)
394-
>>> complex('\t( -1.23+4.5J )\n')
395-
(-1.23+4.5j)
396-
>>> complex('-Infinity+NaNj')
397-
(-inf+nanj)
398-
>>> complex(1.23)
399-
(1.23+0j)
400-
>>> complex(imag=-4.5)
401-
-4.5j
402-
>>> complex(-1.23, 4.5)
403-
(-1.23+4.5j)
404-
405-
If the argument is a string, it must contain either a real part (in the
406-
same format as for :func:`float`) or an imaginary part (in the same
407-
format but with a ``'j'`` or ``'J'`` suffix), or both real and imaginary
408-
parts (the sign of the imaginary part is mandatory in this case).
409-
The string can optionally be surrounded by whitespaces and the round
410-
parentheses ``'('`` and ``')'``, which are ignored.
411-
The string must not contain whitespace between ``'+'``, ``'-'``, the
412-
``'j'`` or ``'J'`` suffix, and the decimal number.
413-
For example, ``complex('1+2j')`` is fine, but ``complex('1 + 2j')`` raises
414-
:exc:`ValueError`.
415-
More precisely, the input must conform to the :token:`~float:complexvalue`
416-
production rule in the following grammar, after parentheses and leading and
417-
trailing whitespace characters are removed:
388+
>>> complex('+1.23')
389+
(1.23+0j)
390+
>>> complex('-4.5j')
391+
-4.5j
392+
>>> complex('-1.23+4.5j')
393+
(-1.23+4.5j)
394+
>>> complex('\t( -1.23+4.5J )\n')
395+
(-1.23+4.5j)
396+
>>> complex('-Infinity+NaNj')
397+
(-inf+nanj)
398+
>>> complex(1.23)
399+
(1.23+0j)
400+
>>> complex(imag=-4.5)
401+
-4.5j
402+
>>> complex(-1.23, 4.5)
403+
(-1.23+4.5j)
404+
405+
If the argument is a string, it must contain either a real part (in the
406+
same format as for :func:`float`) or an imaginary part (in the same
407+
format but with a ``'j'`` or ``'J'`` suffix), or both real and imaginary
408+
parts (the sign of the imaginary part is mandatory in this case).
409+
The string can optionally be surrounded by whitespace and parentheses
410+
(``'('`` and ``')'``), which are ignored.
411+
The string must not contain whitespace between the ``'+'``, ``'-'``,
412+
the ``'j'`` or ``'J'`` suffix, and the decimal number.
413+
For example, ``complex('1+2j')`` is fine, but ``complex('1 + 2j')`` raises
414+
:exc:`ValueError`.
415+
416+
More precisely, the input must conform to the :token:`~float:complexvalue`
417+
production rule in the following grammar, after parentheses and leading
418+
and trailing whitespace characters are removed:
419+
420+
.. productionlist:: float
421+
complexvalue: `floatvalue` |
422+
: `floatvalue` ("j" | "J") |
423+
: `floatvalue` `sign` `absfloatvalue` ("j" | "J")
418424

419-
.. productionlist:: float
420-
complexvalue: `floatvalue` |
421-
: `floatvalue` ("j" | "J") |
422-
: `floatvalue` `sign` `absfloatvalue` ("j" | "J")
423425

424426
If the argument is a number, the constructor serves as a numeric
425427
conversion like :class:`int` and :class:`float`.

0 commit comments

Comments
 (0)