Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 8b3f68d

Browse files
author
Anselm Kruis
committed
Merge branch main into main-slp
2 parents eab1146 + 13ed079 commit 8b3f68d

18 files changed

+764
-110
lines changed

‎Doc/library/functions.rst

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,9 +1277,24 @@ are always available. They are listed here in alphabetical order.
12771277
operands, the result has the same type as the operands (after coercion)
12781278
unless the second argument is negative; in that case, all arguments are
12791279
converted to float and a float result is delivered. For example, ``10**2``
1280-
returns ``100``, but ``10**-2`` returns ``0.01``. If the second argument is
1281-
negative, the third argument must be omitted. If *z* is present, *x* and *y*
1282-
must be of integer types, and *y* must be non-negative.
1280+
returns ``100``, but ``10**-2`` returns ``0.01``.
1281+
1282+
For :class:`int` operands *x* and *y*, if *z* is present, *z* must also be
1283+
of integer type and *z* must be nonzero. If *z* is present and *y* is
1284+
negative, *x* must be relatively prime to *z*. In that case, ``pow(inv_x,
1285+
-y, z)`` is returned, where *inv_x* is an inverse to *x* modulo *z*.
1286+
1287+
Here's an example of computing an inverse for ``38`` modulo ``97``::
1288+
1289+
>>> pow(38, -1, 97)
1290+
23
1291+
>>> 23 * 38 % 97 == 1
1292+
True
1293+
1294+
.. versionchanged:: 3.8
1295+
For :class:`int` operands, the three-argument form of ``pow`` now allows
1296+
the second argument to be negative, permitting computation of modular
1297+
inverses.
12831298

12841299

12851300
.. function:: print(*objects, sep=' ', end='\\n', file=sys.stdout, flush=False)

‎Doc/library/math.rst

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ Number-theoretic and representation functions
3636
:class:`~numbers.Integral` value.
3737

3838

39+
.. function:: comb(n, k)
40+
41+
Return the number of ways to choose *k* items from *n* items without repetition
42+
and without order.
43+
44+
Also called the binomial coefficient. It is mathematically equal to the expression
45+
``n! / (k! (n - k)!)``. It is equivalent to the coefficient of the *k*-th term in the
46+
polynomial expansion of the expression ``(1 + x) ** n``.
47+
48+
Raises :exc:`TypeError` if the arguments not integers.
49+
Raises :exc:`ValueError` if the arguments are negative or if *k* > *n*.
50+
51+
.. versionadded:: 3.8
52+
53+
3954
.. function:: copysign(x, y)
4055

4156
Return a float with the magnitude (absolute value) of *x* but the sign of
@@ -192,6 +207,19 @@ Number-theoretic and representation functions
192207
of *x* and are floats.
193208

194209

210+
.. function:: perm(n, k)
211+
212+
Return the number of ways to choose *k* items from *n* items
213+
without repetition and with order.
214+
215+
It is mathematically equal to the expression ``n! / (n - k)!``.
216+
217+
Raises :exc:`TypeError` if the arguments not integers.
218+
Raises :exc:`ValueError` if the arguments are negative or if *k* > *n*.
219+
220+
.. versionadded:: 3.8
221+
222+
195223
.. function:: prod(iterable, *, start=1)
196224

197225
Calculate the product of all the elements in the input *iterable*.
@@ -232,21 +260,6 @@ Number-theoretic and representation functions
232260
:meth:`x.__trunc__() <object.__trunc__>`.
233261

234262

235-
.. function:: comb(n, k)
236-
237-
Return the number of ways to choose *k* items from *n* items without repetition
238-
and without order.
239-
240-
Also called the binomial coefficient. It is mathematically equal to the expression
241-
``n! / (k! (n - k)!)``. It is equivalent to the coefficient of the *k*-th term in the
242-
polynomial expansion of the expression ``(1 + x) ** n``.
243-
244-
Raises :exc:`TypeError` if the arguments not integers.
245-
Raises :exc:`ValueError` if the arguments are negative or if *k* > *n*.
246-
247-
.. versionadded:: 3.8
248-
249-
250263
Note that :func:`frexp` and :func:`modf` have a different call/return pattern
251264
than their C equivalents: they take a single argument and return a pair of
252265
values, rather than returning their second return value through an 'output

‎Doc/library/typing.rst

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ The module defines the following classes, functions and decorators:
637637

638638
A generic version of :class:`collections.abc.Collection`
639639

640-
.. versionadded:: 3.6
640+
.. versionadded:: 3.6.0
641641

642642
.. class:: AbstractSet(Sized, Collection[T_co])
643643

@@ -681,6 +681,7 @@ The module defines the following classes, functions and decorators:
681681

682682
A generic version of :class:`collections.deque`.
683683

684+
.. versionadded:: 3.5.4
684685
.. versionadded:: 3.6.1
685686

686687
.. class:: List(list, MutableSequence[T])
@@ -730,6 +731,8 @@ The module defines the following classes, functions and decorators:
730731

731732
A generic version of :class:`collections.abc.Awaitable`.
732733

734+
.. versionadded:: 3.5.2
735+
733736
.. class:: Coroutine(Awaitable[V_co], Generic[T_co T_contra, V_co])
734737

735738
A generic version of :class:`collections.abc.Coroutine`.
@@ -743,25 +746,33 @@ The module defines the following classes, functions and decorators:
743746
async def bar() -> None:
744747
x = await c # type: int
745748

749+
.. versionadded:: 3.5.3
750+
746751
.. class:: AsyncIterable(Generic[T_co])
747752

748753
A generic version of :class:`collections.abc.AsyncIterable`.
749754

755+
.. versionadded:: 3.5.2
756+
750757
.. class:: AsyncIterator(AsyncIterable[T_co])
751758

752759
A generic version of :class:`collections.abc.AsyncIterator`.
753760

761+
.. versionadded:: 3.5.2
762+
754763
.. class:: ContextManager(Generic[T_co])
755764

756765
A generic version of :class:`contextlib.AbstractContextManager`.
757766

758-
.. versionadded:: 3.6
767+
.. versionadded:: 3.5.4
768+
.. versionadded:: 3.6.0
759769

760770
.. class:: AsyncContextManager(Generic[T_co])
761771

762772
A generic version of :class:`contextlib.AbstractAsyncContextManager`.
763773

764-
.. versionadded:: 3.6
774+
.. versionadded:: 3.5.4
775+
.. versionadded:: 3.6.2
765776

766777
.. class:: Dict(dict, MutableMapping[KT, VT])
767778

@@ -790,12 +801,14 @@ The module defines the following classes, functions and decorators:
790801

791802
A generic version of :class:`collections.Counter`.
792803

804+
.. versionadded:: 3.5.4
793805
.. versionadded:: 3.6.1
794806

795807
.. class:: ChainMap(collections.ChainMap, MutableMapping[KT, VT])
796808

797809
A generic version of :class:`collections.ChainMap`.
798810

811+
.. versionadded:: 3.5.4
799812
.. versionadded:: 3.6.1
800813

801814
.. class:: Generator(Iterator[T_co], Generic[T_co, T_contra, V_co])
@@ -860,7 +873,7 @@ The module defines the following classes, functions and decorators:
860873
yield start
861874
start = await increment(start)
862875

863-
.. versionadded:: 3.5.4
876+
.. versionadded:: 3.6.1
864877

865878
.. class:: Text
866879

@@ -1166,6 +1179,7 @@ The module defines the following classes, functions and decorators:
11661179
raise RuntimeError('no way')
11671180

11681181
.. versionadded:: 3.5.4
1182+
.. versionadded:: 3.6.2
11691183

11701184
.. data:: Union
11711185

‎Doc/whatsnew/3.8.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,12 @@ Other Language Changes
304304
* Added new ``replace()`` method to the code type (:class:`types.CodeType`).
305305
(Contributed by Victor Stinner in :issue:`37032`.)
306306

307+
* For integers, the three-argument form of the :func:`pow` function now permits
308+
the exponent to be negative in the case where the base is relatively prime to
309+
the modulus. It then computes a modular inverse to the base when the exponent
310+
is ``-1``, and a suitable power of that inverse for other negative exponents.
311+
(Contributed by Mark Dickinson in :issue:`36027`.)
312+
307313

308314
New Modules
309315
===========

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /