Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 83c0ae5

Browse files
committed
Address most of Ezio's comments. str/bytes/bytearray docs still need consolidation
1 parent 5b27c53 commit 83c0ae5

2 files changed

Lines changed: 247 additions & 189 deletions

File tree

Doc/library/functions.rst

Lines changed: 20 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ are always available. They are listed here in alphabetical order.
1717
:func:`bin` :func:`eval` :func:`int` :func:`open` :func:`str`
1818
:func:`bool` :func:`exec` :func:`isinstance` :func:`ord` :func:`sum`
1919
:func:`bytearray` :func:`filter` :func:`issubclass` :func:`pow` :func:`super`
20-
:func:`bytes` :func:`float` :func:`iter` :func:`print` :func:`tuple`
20+
:func:`bytes` :func:`float` :func:`iter` :func:`print` |func-tuple|_
2121
:func:`callable` :func:`format` :func:`len` :func:`property` :func:`type`
22-
:func:`chr` |func-frozenset|_ :func:`list` :func:`range` :func:`vars`
22+
:func:`chr` |func-frozenset|_ |func-list|_ |func-range|_ :func:`vars`
2323
:func:`classmethod` :func:`getattr` :func:`locals` :func:`repr` :func:`zip`
2424
:func:`compile` :func:`globals` :func:`map` :func:`reversed` :func:`__import__`
2525
:func:`complex` :func:`hasattr` :func:`max` :func:`round`
@@ -33,6 +33,9 @@ are always available. They are listed here in alphabetical order.
3333
.. |func-frozenset| replace:: ``frozenset()``
3434
.. |func-memoryview| replace:: ``memoryview()``
3535
.. |func-set| replace:: ``set()``
36+
.. |func-list| replace:: ``list()``
37+
.. |func-tuple| replace:: ``tuple()``
38+
.. |func-range| replace:: ``range()``
3639

3740

3841
.. function:: abs(x)
@@ -93,6 +96,7 @@ are always available. They are listed here in alphabetical order.
9396
.. index:: pair: Boolean; type
9497

9598

99+
.. _func-bytearray:
96100
.. function:: bytearray([source[, encoding[, errors]]])
97101

98102
Return a new array of bytes. The :class:`bytearray` type is a mutable
@@ -119,6 +123,7 @@ are always available. They are listed here in alphabetical order.
119123
Without an argument, an array of size 0 is created.
120124

121125

126+
.. _func-bytes:
122127
.. function:: bytes([source[, encoding[, errors]]])
123128

124129
Return a new "bytes" object, which is an immutable sequence of integers in
@@ -692,16 +697,12 @@ are always available. They are listed here in alphabetical order.
692697
sequence (string, tuple or list) or a mapping (dictionary).
693698

694699

700+
.. _func-list:
695701
.. function:: list([iterable])
702+
:noindex:
696703

697-
Return a list whose items are the same and in the same order as *iterable*'s
698-
items. *iterable* may be either a sequence, a container that supports
699-
iteration, or an iterator object. If *iterable* is already a list, a copy is
700-
made and returned, similar to ``iterable[:]``. For instance, ``list('abc')``
701-
returns ``['a', 'b', 'c']`` and ``list( (1, 2, 3) )`` returns ``[1, 2, 3]``.
702-
If no argument is given, returns a new empty list, ``[]``.
703-
704-
:class:`list` is a mutable sequence type, as documented in :ref:`typesseq`.
704+
Rather than being a function, :class:`list` is actually a mutable
705+
sequence type, as documented in :ref:`typesseq`.
705706

706707

707708
.. function:: locals()
@@ -1059,79 +1060,12 @@ are always available. They are listed here in alphabetical order.
10591060
``fdel`` corresponding to the constructor arguments.
10601061

10611062

1062-
.. XXX does accept objects with __index__ too
1063+
.. _func-range:
10631064
.. function:: range([start,] stop[, step])
1065+
:noindex:
10641066

1065-
This is a versatile function to create iterables yielding arithmetic
1066-
progressions. It is most often used in :keyword:`for` loops. The arguments
1067-
must be integers. If the *step* argument is omitted, it defaults to ``1``.
1068-
If the *start* argument is omitted, it defaults to ``0``. The full form
1069-
returns an iterable of integers ``[start, start + step, start + 2 * step,
1070-
...]``. If *step* is positive, the last element is the largest ``start + i *
1071-
step`` less than *stop*; if *step* is negative, the last element is the
1072-
smallest ``start + i * step`` greater than *stop*. *step* must not be zero
1073-
(or else :exc:`ValueError` is raised). Range objects have read-only data
1074-
attributes :attr:`start`, :attr:`stop` and :attr:`step` which return the
1075-
argument values (or their default). Example:
1076-
1077-
>>> list(range(10))
1078-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
1079-
>>> list(range(1, 11))
1080-
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
1081-
>>> list(range(0, 30, 5))
1082-
[0, 5, 10, 15, 20, 25]
1083-
>>> list(range(0, 10, 3))
1084-
[0, 3, 6, 9]
1085-
>>> list(range(0, -10, -1))
1086-
[0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
1087-
>>> list(range(0))
1088-
[]
1089-
>>> list(range(1, 0))
1090-
[]
1091-
1092-
Range objects implement the :class:`collections.Sequence` ABC, and provide
1093-
features such as containment tests, element index lookup, slicing and
1094-
support for negative indices (see :ref:`typesseq`):
1095-
1096-
>>> r = range(0, 20, 2)
1097-
>>> r
1098-
range(0, 20, 2)
1099-
>>> 11 in r
1100-
False
1101-
>>> 10 in r
1102-
True
1103-
>>> r.index(10)
1104-
5
1105-
>>> r[5]
1106-
10
1107-
>>> r[:5]
1108-
range(0, 10, 2)
1109-
>>> r[-1]
1110-
18
1111-
1112-
Testing range objects for equality with ``==`` and ``!=`` compares
1113-
them as sequences. That is, two range objects are considered equal if
1114-
they represent the same sequence of values. (Note that two range
1115-
objects that compare equal might have different :attr:`start`,
1116-
:attr:`stop` and :attr:`step` attributes, for example ``range(0) ==
1117-
range(2, 1, 3)`` or ``range(0, 3, 2) == range(0, 4, 2)``.)
1118-
1119-
Ranges containing absolute values larger than :data:`sys.maxsize` are permitted
1120-
but some features (such as :func:`len`) will raise :exc:`OverflowError`.
1121-
1122-
.. versionchanged:: 3.2
1123-
Implement the Sequence ABC.
1124-
Support slicing and negative indices.
1125-
Test integers for membership in constant time instead of iterating
1126-
through all items.
1127-
1128-
.. versionchanged:: 3.3
1129-
Define '==' and '!=' to compare range objects based on the
1130-
sequence of values they define (instead of comparing based on
1131-
object identity).
1132-
1133-
.. versionadded:: 3.3
1134-
The :attr:`start`, :attr:`stop` and :attr:`step` attributes.
1067+
Rather than being a function, :class:`range` is actually an immutable
1068+
sequence type, as documented in :ref:`typesseq`.
11351069

11361070

11371071
.. function:: repr(object)
@@ -1251,6 +1185,7 @@ are always available. They are listed here in alphabetical order.
12511185
standard type hierarchy in :ref:`types`.
12521186

12531187

1188+
.. _func-str:
12541189
.. function:: str([object[, encoding[, errors]]])
12551190

12561191
Return a string version of an object, using one of the following modes:
@@ -1352,16 +1287,12 @@ are always available. They are listed here in alphabetical order.
13521287
<http://rhettinger.wordpress.com/2011/05/26/super-considered-super/>`_.
13531288

13541289

1290+
.. _func-tuple:
13551291
.. function:: tuple([iterable])
1292+
:noindex:
13561293

1357-
Return a tuple whose items are the same and in the same order as *iterable*'s
1358-
items. *iterable* may be a sequence, a container that supports iteration, or an
1359-
iterator object. If *iterable* is already a tuple, it is returned unchanged.
1360-
For instance, ``tuple('abc')`` returns ``('a', 'b', 'c')`` and ``tuple([1, 2,
1361-
3])`` returns ``(1, 2, 3)``. If no argument is given, returns a new empty
1362-
tuple, ``()``.
1363-
1364-
:class:`tuple` is an immutable sequence type, as documented in :ref:`typesseq`.
1294+
Rather than being a function, :class:`tuple` is actually an immutable
1295+
sequence type, as documented in :ref:`typesseq`.
13651296

13661297

13671298
.. function:: type(object)

0 commit comments

Comments
 (0)