From 43a63cc49048c12467b48a108af651db55a4582d Mon Sep 17 00:00:00 2001 From: Yzi-Li <1538321957@qq.com> Date: Sat, 31 May 2025 21:00:10 +0800 Subject: [PATCH 1/2] Add note about s[i] --- Doc/library/stdtypes.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index f0b4b09ff10dce..47c5fc4054899d 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1018,7 +1018,7 @@ operations have the same priority as the corresponding numeric operations. [3]_ | ``s * n`` or | equivalent to adding *s* to | (2)(7) | | ``n * s`` | itself *n* times | | +--------------------------+--------------------------------+----------+ -| ``s[i]`` | *i*\ th item of *s*, origin 0 | \(3) | +| ``s[i]`` | *i*\ th item of *s*, origin 0 | (3)(9) | +--------------------------+--------------------------------+----------+ | ``s[i:j]`` | slice of *s* from *i* to *j* | (3)(4) | +--------------------------+--------------------------------+----------+ @@ -1150,6 +1150,10 @@ Notes: without copying any data and with the returned index being relative to the start of the sequence rather than the start of the slice. +(9) + If the sequence is empty or *i* is outside the sequence range, :exc:`IndexError` + will be raised. + .. _typesseq-immutable: From 8566fbb589f27dbd37067b2e885811dfffb1129b Mon Sep 17 00:00:00 2001 From: Yongzi Li <1538321957@qq.com> Date: Sat, 31 May 2025 21:16:30 +0800 Subject: [PATCH 2/2] Update Doc/library/stdtypes.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Doc/library/stdtypes.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 47c5fc4054899d..b75e5ceecf874e 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1151,8 +1151,7 @@ Notes: the start of the sequence rather than the start of the slice. (9) - If the sequence is empty or *i* is outside the sequence range, :exc:`IndexError` - will be raised. + An :exc:`IndexError` is raised if *i* is outside the sequence range. .. _typesseq-immutable: