[3.13] GH-138465: Improve documentation for common sequence methods (GH-138474) (#138567)
Some checks are pending
Tests / (push) Blocked by required conditions
Tests / Windows MSI (push) Blocked by required conditions
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Check if the ABI has changed (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / Android (aarch64) (push) Blocked by required conditions
Tests / Android (x86_64) (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Sanitizers (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Adam Turner 2025-09-05 22:39:32 +01:00 committed by GitHub
parent bb64bc357f
commit e7bb98a173
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 182 additions and 120 deletions

View file

@ -567,7 +567,7 @@ This example, as usual, demonstrates some new Python features:
Different types define different methods. Methods of different types may have
the same name without causing ambiguity. (It is possible to define your own
object types and methods, using *classes*, see :ref:`tut-classes`)
The method :meth:`!append` shown in the example is defined for list objects; it
The method :meth:`~list.append` shown in the example is defined for list objects; it
adds a new element at the end of the list. In this example it is equivalent to
``result = result + [a]``, but more efficient.

View file

@ -142,8 +142,8 @@ Using Lists as Stacks
The list methods make it very easy to use a list as a stack, where the last
element added is the first element retrieved ("last-in, first-out"). To add an
item to the top of the stack, use :meth:`!append`. To retrieve an item from the
top of the stack, use :meth:`!pop` without an explicit index. For example::
item to the top of the stack, use :meth:`~list.append`. To retrieve an item from the
top of the stack, use :meth:`~list.pop` without an explicit index. For example::
>>> stack = [3, 4, 5]
>>> stack.append(6)
@ -340,7 +340,7 @@ The :keyword:`!del` statement
=============================
There is a way to remove an item from a list given its index instead of its
value: the :keyword:`del` statement. This differs from the :meth:`!pop` method
value: the :keyword:`del` statement. This differs from the :meth:`~list.pop` method
which returns a value. The :keyword:`!del` statement can also be used to remove
slices from a list or clear the entire list (which we did earlier by assignment
of an empty list to the slice). For example::
@ -500,8 +500,8 @@ any immutable type; strings and numbers can always be keys. Tuples can be used
as keys if they contain only strings, numbers, or tuples; if a tuple contains
any mutable object either directly or indirectly, it cannot be used as a key.
You can't use lists as keys, since lists can be modified in place using index
assignments, slice assignments, or methods like :meth:`!append` and
:meth:`!extend`.
assignments, slice assignments, or methods like :meth:`~list.append` and
:meth:`~list.extend`.
It is best to think of a dictionary as a set of *key: value* pairs,
with the requirement that the keys are unique (within one dictionary). A pair of

View file

@ -420,7 +420,7 @@ type, i.e. it is possible to change their content::
[1, 8, 27, 64, 125]
You can also add new items at the end of the list, by using
the :meth:`!list.append` *method* (we will see more about methods later)::
the :meth:`list.append` *method* (we will see more about methods later)::
>>> cubes.append(216) # add the cube of 6
>>> cubes.append(7 ** 3) # and the cube of 7