@@ -1018,7 +1018,7 @@ operations have the same priority as the corresponding numeric operations. [3]_
10181018| ``s * n `` or | equivalent to adding *s * to | (2)(7) |
10191019| ``n * s `` | itself *n * times | |
10201020+--------------------------+--------------------------------+----------+
1021- | ``s[i] `` | *i *\ th item of *s *, origin 0 | (3)(9 ) |
1021+ | ``s[i] `` | *i *\ th item of *s *, origin 0 | (3)(8 ) |
10221022+--------------------------+--------------------------------+----------+
10231023| ``s[i:j] `` | slice of *s * from *i * to *j * | (3)(4) |
10241024+--------------------------+--------------------------------+----------+
@@ -1031,13 +1031,36 @@ operations have the same priority as the corresponding numeric operations. [3]_
10311031+--------------------------+--------------------------------+----------+
10321032| ``max(s) `` | largest item of *s * | |
10331033+--------------------------+--------------------------------+----------+
1034- | ``s.index(x[, i[, j]]) `` | index of the first occurrence | \( 8) |
1035- | | of *x * in *s * (at or after | |
1036- | | index *i * and before index *j *)| |
1037- +--------------------------+--------------------------------+----------+
1038- | ``s.count(x) `` | total number of occurrences of | |
1039- | | *x * in *s * | |
1040- +--------------------------+--------------------------------+----------+
1034+
1035+ .. method :: list.count(value, /)
1036+ range.count(value, /)
1037+ tuple.count(value, /)
1038+ :no-contents-entry:
1039+ :no-index-entry:
1040+ :no-typesetting:
1041+ .. method :: sequence.count(value, /)
1042+
1043+ Return the total number of occurrences of *value * in *sequence *.
1044+
1045+ .. method :: list.index(value, start=0, stop=None, /)
1046+ range.index(value, start=0, stop=None, /)
1047+ tuple.index(value, start=0, stop=None, /)
1048+ :no-contents-entry:
1049+ :no-index-entry:
1050+ :no-typesetting:
1051+ .. method :: sequence.index(value, start=0, stop=None, /)
1052+
1053+ Return the index of the first occurrence of *value * in *sequence *.
1054+
1055+ Raises :exc: `ValueError ` if *value * is not found in *sequence *.
1056+
1057+ The *start * or *stop * arguments allow for efficient searching
1058+ of subsections of the sequence, beginning at *start * and ending at *stop *.
1059+ This is roughly equivalent to ``start + sequence[start:stop].index(value) ``,
1060+ only without copying any data.
1061+
1062+ .. caution ::
1063+ Not all sequence types support passing the *start * and *stop * arguments.
10411064
10421065Sequences of the same type also support comparisons. In particular, tuples
10431066and lists are compared lexicographically by comparing corresponding elements.
@@ -1143,14 +1166,6 @@ Notes:
11431166 concatenation or repetition.
11441167
11451168(8)
1146- ``index `` raises :exc: `ValueError ` when *x * is not found in *s *.
1147- Not all implementations support passing the additional arguments *i * and *j *.
1148- These arguments allow efficient searching of subsections of the sequence. Passing
1149- the extra arguments is roughly equivalent to using ``s[i:j].index(x) ``, only
1150- without copying any data and with the returned index being relative to
1151- the start of the sequence rather than the start of the slice.
1152-
1153- (9)
11541169 An :exc: `IndexError ` is raised if *i * is outside the sequence range.
11551170
11561171
@@ -1233,38 +1248,101 @@ accepts integers that meet the value restriction ``0 <= x <= 255``).
12331248| ``del s[i:j:k] `` | removes the elements of | |
12341249| | ``s[i:j:k] `` from the list | |
12351250+------------------------------+--------------------------------+---------------------+
1236- | ``s.append(x) `` | appends *x * to the end of the | |
1237- | | sequence (same as | |
1238- | | ``s[len(s):len(s)] = [x] ``) | |
1239- +------------------------------+--------------------------------+---------------------+
1240- | ``s.clear() `` | removes all items from *s * | \( 5) |
1241- | | (same as ``del s[:] ``) | |
1242- +------------------------------+--------------------------------+---------------------+
1243- | ``s.copy() `` | creates a shallow copy of *s * | \( 5) |
1244- | | (same as ``s[:] ``) | |
1245- +------------------------------+--------------------------------+---------------------+
1246- | ``s.extend(t) `` or | extends *s * with the | |
1247- | ``s += t `` | contents of *t * (for the | |
1251+ | ``s += t `` | extends *s * with the | |
1252+ | | contents of *t * (for the | |
12481253| | most part the same as | |
12491254| | ``s[len(s):len(s)] = t ``) | |
12501255+------------------------------+--------------------------------+---------------------+
1251- | ``s *= n `` | updates *s * with its contents | \( 6 ) |
1256+ | ``s *= n `` | updates *s * with its contents | \( 2 ) |
12521257| | repeated *n * times | |
12531258+------------------------------+--------------------------------+---------------------+
1254- | ``s.insert(i, x) `` | inserts *x * into *s * at the | |
1255- | | index given by *i * | |
1256- | | (same as ``s[i:i] = [x] ``) | |
1257- +------------------------------+--------------------------------+---------------------+
1258- | ``s.pop() `` or ``s.pop(i) `` | retrieves the item at *i * and | \( 2) |
1259- | | also removes it from *s * | |
1260- +------------------------------+--------------------------------+---------------------+
1261- | ``s.remove(x) `` | removes the first item from | \( 3) |
1262- | | *s * where ``s[i] `` is equal to | |
1263- | | *x * | |
1264- +------------------------------+--------------------------------+---------------------+
1265- | ``s.reverse() `` | reverses the items of *s * in | \( 4) |
1266- | | place | |
1267- +------------------------------+--------------------------------+---------------------+
1259+
1260+ .. method :: bytearray.append(value, /)
1261+ list.append(value, /)
1262+ :no-contents-entry:
1263+ :no-index-entry:
1264+ :no-typesetting:
1265+ .. method :: sequence.append(value, /)
1266+
1267+ Append *value * to the end of the sequence
1268+ This is equivalent to writing ``seq[len(seq):len(seq)] = value ``.
1269+
1270+ .. method :: bytearray.clear()
1271+ list.clear()
1272+ :no-contents-entry:
1273+ :no-index-entry:
1274+ :no-typesetting:
1275+ .. method :: sequence.clear()
1276+
1277+ Remove all items from *sequence *.
1278+ This is equivalent to writing ``del sequence[:] ``.
1279+
1280+ .. method :: bytearray.copy()
1281+ list.copy()
1282+ :no-contents-entry:
1283+ :no-index-entry:
1284+ :no-typesetting:
1285+ .. method :: sequence.copy()
1286+
1287+ Create a shallow copy of *sequence *.
1288+ This is equivalent to writing ``sequence[:] ``.
1289+
1290+ .. hint :: The :meth:`!copy` method is not part of the
1291+ :class: `~collections.abc.MutableSequence ` :class: `~abc.ABC `,
1292+ but most concrete mutable sequence types provide it.
1293+
1294+ .. method :: bytearray.extend(iterable, /)
1295+ list.extend(iterable, /)
1296+ :no-contents-entry:
1297+ :no-index-entry:
1298+ :no-typesetting:
1299+ .. method :: sequence.extend(iterable, /)
1300+
1301+ Extend *sequence * with the contents of *iterable *.
1302+ For the most part, this is the same as writing
1303+ ``seq[len(seq):len(seq)] = iterable ``.
1304+
1305+ .. method :: bytearray.insert(index, value, /)
1306+ list.insert(index, value, /)
1307+ :no-contents-entry:
1308+ :no-index-entry:
1309+ :no-typesetting:
1310+ .. method :: sequence.insert(index, value, /)
1311+
1312+ Insert *value * into *sequence * at the given *index *.
1313+ This is equivalent to writing ``sequence[index:index] = [value] ``.
1314+
1315+ .. method :: bytearray.pop(index=-1, /)
1316+ list.pop(index=-1, /)
1317+ :no-contents-entry:
1318+ :no-index-entry:
1319+ :no-typesetting:
1320+ .. method :: sequence.pop(index=-1, /)
1321+
1322+ Retrieve the item at *index * and also removes it from *sequence *.
1323+ By default, the last item in *sequence * is removed and returned.
1324+
1325+ .. method :: bytearray.remove(value, /)
1326+ list.remove(value, /)
1327+ :no-contents-entry:
1328+ :no-index-entry:
1329+ :no-typesetting:
1330+ .. method :: sequence.remove(value, /)
1331+
1332+ Remove the first item from *sequence * where ``sequence[i] == value ``.
1333+
1334+ Raises :exc: `ValueError ` if *value * is not found in *sequence *.
1335+
1336+ .. method :: bytearray.reverse()
1337+ list.reverse()
1338+ :no-contents-entry:
1339+ :no-index-entry:
1340+ :no-typesetting:
1341+ .. method :: sequence.reverse()
1342+
1343+ Reverse the items of *sequence * in place.
1344+ This method maintains economy of space when reversing a large sequence.
1345+ To remind users that it operates by side-effect, it returns ``None ``.
12681346
12691347
12701348Notes:
@@ -1273,28 +1351,6 @@ Notes:
12731351 If *k * is not equal to ``1 ``, *t * must have the same length as the slice it is replacing.
12741352
12751353(2)
1276- The optional argument *i * defaults to ``-1 ``, so that by default the last
1277- item is removed and returned.
1278-
1279- (3)
1280- :meth: `remove ` raises :exc: `ValueError ` when *x * is not found in *s *.
1281-
1282- (4)
1283- The :meth: `reverse ` method modifies the sequence in place for economy of
1284- space when reversing a large sequence. To remind users that it operates by
1285- side effect, it does not return the reversed sequence.
1286-
1287- (5)
1288- :meth: `clear ` and :meth: `!copy ` are included for consistency with the
1289- interfaces of mutable containers that don't support slicing operations
1290- (such as :class: `dict ` and :class: `set `). :meth: `!copy ` is not part of the
1291- :class: `collections.abc.MutableSequence ` ABC, but most concrete
1292- mutable sequence classes provide it.
1293-
1294- .. versionadded :: 3.3
1295- :meth: `clear ` and :meth: `!copy ` methods.
1296-
1297- (6)
12981354 The value *n * is an integer, or an object implementing
12991355 :meth: `~object.__index__ `. Zero and negative values of *n * clear
13001356 the sequence. Items in the sequence are not copied; they are referenced
@@ -5761,9 +5817,10 @@ Methods
57615817
57625818.. index :: pair: object; method
57635819
5764- Methods are functions that are called using the attribute notation. There are
5765- two flavors: :ref: `built-in methods <builtin-methods >` (such as :meth: `append `
5766- on lists) and :ref: `class instance method <instance-methods >`.
5820+ Methods are functions that are called using the attribute notation.
5821+ There are two flavors: :ref: `built-in methods <builtin-methods >`
5822+ (such as :meth: `~list.append ` on lists)
5823+ and :ref: `class instance method <instance-methods >`.
57675824Built-in methods are described with the types that support them.
57685825
57695826If you access a method (a function defined in a class namespace) through an
0 commit comments