mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
GH-100101: Clarify documentation of zip's strict option (GH-100103)
This commit is contained in:
parent
c4c5790120
commit
cf1c098180
1 changed files with 13 additions and 3 deletions
|
@ -1923,14 +1923,24 @@ are always available. They are listed here in alphabetical order.
|
|||
>>> list(zip(('a', 'b', 'c'), (1, 2, 3), strict=True))
|
||||
[('a', 1), ('b', 2), ('c', 3)]
|
||||
|
||||
Unlike the default behavior, it checks that the lengths of iterables are
|
||||
identical, raising a :exc:`ValueError` if they aren't:
|
||||
Unlike the default behavior, it raises a :exc:`ValueError` if one iterable
|
||||
is exhausted before the others:
|
||||
|
||||
>>> list(zip(range(3), ['fee', 'fi', 'fo', 'fum'], strict=True))
|
||||
>>> for item in zip(range(3), ['fee', 'fi', 'fo', 'fum'], strict=True): # doctest: +SKIP
|
||||
... print(item)
|
||||
...
|
||||
(0, 'fee')
|
||||
(1, 'fi')
|
||||
(2, 'fo')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: zip() argument 2 is longer than argument 1
|
||||
|
||||
..
|
||||
This doctest is disabled because doctest does not support capturing
|
||||
output and exceptions in the same code unit.
|
||||
https://github.com/python/cpython/issues/65382
|
||||
|
||||
Without the ``strict=True`` argument, any bug that results in iterables of
|
||||
different lengths will be silenced, possibly manifesting as a hard-to-find
|
||||
bug in another part of the program.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue