Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(13)

Delta Between Two Patch Sets: Doc/library/functions.rst

Issue 19362: Documentation for len() fails to mention that it works on sets
Left Patch Set: Created 6 years, 4 months ago
Right Patch Set: Created 6 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | Python/bltinmodule.c » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 .. XXX document all delegations to __special__ methods 1 .. XXX document all delegations to __special__ methods
2 .. _built-in-funcs: 2 .. _built-in-funcs:
3 3
4 Built-in Functions 4 Built-in Functions
5 ================== 5 ==================
6 6
7 The Python interpreter has a number of functions and types built into it that 7 The Python interpreter has a number of functions and types built into it that
8 are always available. They are listed here in alphabetical order. 8 are always available. They are listed here in alphabetical order.
9 9
10 =================== ================= ================== ================ == ================== 10 =================== ================= ================== ================ == ==================
(...skipping 30 matching lines...) Expand all
41 41
42 .. function:: abs(x) 42 .. function:: abs(x)
43 43
44 Return the absolute value of a number. The argument may be an 44 Return the absolute value of a number. The argument may be an
45 integer or a floating point number. If the argument is a complex number, its 45 integer or a floating point number. If the argument is a complex number, its
46 magnitude is returned. 46 magnitude is returned.
47 47
48 48
49 .. function:: all(iterable) 49 .. function:: all(iterable)
50 50
51 Return True if all elements of the *iterable* are true (or if the iterable 51 Return ``True`` if all elements of the *iterable* are true (or if the iterabl e
52 is empty). Equivalent to:: 52 is empty). Equivalent to::
53 53
54 def all(iterable): 54 def all(iterable):
55 for element in iterable: 55 for element in iterable:
56 if not element: 56 if not element:
57 return False 57 return False
58 return True 58 return True
59 59
60 60
61 .. function:: any(iterable) 61 .. function:: any(iterable)
62 62
63 Return True if any element of the *iterable* is true. If the iterable 63 Return ``True`` if any element of the *iterable* is true. If the iterable
64 is empty, return False. Equivalent to:: 64 is empty, return ``False``. Equivalent to::
65 65
66 def any(iterable): 66 def any(iterable):
67 for element in iterable: 67 for element in iterable:
68 if element: 68 if element:
69 return True 69 return True
70 return False 70 return False
71 71
72 72
73 .. function:: ascii(object) 73 .. function:: ascii(object)
74 74
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 Class methods are different than C++ or Java static methods. If you want thos e, 186 Class methods are different than C++ or Java static methods. If you want thos e,
187 see :func:`staticmethod` in this section. 187 see :func:`staticmethod` in this section.
188 188
189 For more information on class methods, consult the documentation on the stand ard 189 For more information on class methods, consult the documentation on the stand ard
190 type hierarchy in :ref:`types`. 190 type hierarchy in :ref:`types`.
191 191
192 192
193 .. function:: compile(source, filename, mode, flags=0, dont_inherit=False, optim ize=-1) 193 .. function:: compile(source, filename, mode, flags=0, dont_inherit=False, optim ize=-1)
194 194
195 Compile the *source* into a code or AST object. Code objects can be executed 195 Compile the *source* into a code or AST object. Code objects can be executed
196 by :func:`exec` or :func:`eval`. *source* can either be a string or an AST 196 by :func:`exec` or :func:`eval`. *source* can either be a normal string, a
197 object. Refer to the :mod:`ast` module documentation for information on how 197 byte string, or an AST object. Refer to the :mod:`ast` module documentation
198 to work with AST objects. 198 for information on how to work with AST objects.
199 199
200 The *filename* argument should give the file from which the code was read; 200 The *filename* argument should give the file from which the code was read;
201 pass some recognizable value if it wasn't read from a file (``'<string>'`` is 201 pass some recognizable value if it wasn't read from a file (``'<string>'`` is
202 commonly used). 202 commonly used).
203 203
204 The *mode* argument specifies what kind of code must be compiled; it can be 204 The *mode* argument specifies what kind of code must be compiled; it can be
205 ``'exec'`` if *source* consists of a sequence of statements, ``'eval'`` if it 205 ``'exec'`` if *source* consists of a sequence of statements, ``'eval'`` if it
206 consists of a single expression, or ``'single'`` if it consists of a single 206 consists of a single expression, or ``'single'`` if it consists of a single
207 interactive statement (in the latter case, expression statements that 207 interactive statement (in the latter case, expression statements that
208 evaluate to something other than ``None`` will be printed). 208 evaluate to something other than ``None`` will be printed).
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 ========= =============================================================== 865 ========= ===============================================================
866 Character Meaning 866 Character Meaning
867 ========= =============================================================== 867 ========= ===============================================================
868 ``'r'`` open for reading (default) 868 ``'r'`` open for reading (default)
869 ``'w'`` open for writing, truncating the file first 869 ``'w'`` open for writing, truncating the file first
870 ``'x'`` open for exclusive creation, failing if the file already exists 870 ``'x'`` open for exclusive creation, failing if the file already exists
871 ``'a'`` open for writing, appending to the end of the file if it exists 871 ``'a'`` open for writing, appending to the end of the file if it exists
872 ``'b'`` binary mode 872 ``'b'`` binary mode
873 ``'t'`` text mode (default) 873 ``'t'`` text mode (default)
874 ``'+'`` open a disk file for updating (reading and writing) 874 ``'+'`` open a disk file for updating (reading and writing)
875 ``'U'`` universal newlines mode (for backwards compatibility; should 875 ``'U'`` :term:`universal newlines` mode (deprecated)
876 not be used in new code)
877 ========= =============================================================== 876 ========= ===============================================================
878 877
879 The default mode is ``'r'`` (open for reading text, synonym of ``'rt'``). 878 The default mode is ``'r'`` (open for reading text, synonym of ``'rt'``).
880 For binary read-write access, the mode ``'w+b'`` opens and truncates the file 879 For binary read-write access, the mode ``'w+b'`` opens and truncates the file
881 to 0 bytes. ``'r+b'`` opens the file without truncation. 880 to 0 bytes. ``'r+b'`` opens the file without truncation.
882 881
883 As mentioned in the :ref:`io-overview`, Python distinguishes between binary 882 As mentioned in the :ref:`io-overview`, Python distinguishes between binary
884 and text I/O. Files opened in binary mode (including ``'b'`` in the *mode* 883 and text I/O. Files opened in binary mode (including ``'b'`` in the *mode*
885 argument) return contents as :class:`bytes` objects without any decoding. In 884 argument) return contents as :class:`bytes` objects without any decoding. In
886 text mode (the default, or when ``'t'`` is included in the *mode* argument), 885 text mode (the default, or when ``'t'`` is included in the *mode* argument),
(...skipping 12 matching lines...) Expand all
899 buffering (only usable in text mode), and an integer > 1 to indicate the size 898 buffering (only usable in text mode), and an integer > 1 to indicate the size
900 in bytes of a fixed-size chunk buffer. When no *buffering* argument is 899 in bytes of a fixed-size chunk buffer. When no *buffering* argument is
901 given, the default buffering policy works as follows: 900 given, the default buffering policy works as follows:
902 901
903 * Binary files are buffered in fixed-size chunks; the size of the buffer is 902 * Binary files are buffered in fixed-size chunks; the size of the buffer is
904 chosen using a heuristic trying to determine the underlying device's "block 903 chosen using a heuristic trying to determine the underlying device's "block
905 size" and falling back on :attr:`io.DEFAULT_BUFFER_SIZE`. On many systems, 904 size" and falling back on :attr:`io.DEFAULT_BUFFER_SIZE`. On many systems,
906 the buffer will typically be 4096 or 8192 bytes long. 905 the buffer will typically be 4096 or 8192 bytes long.
907 906
908 * "Interactive" text files (files for which :meth:`~io.IOBase.isatty` 907 * "Interactive" text files (files for which :meth:`~io.IOBase.isatty`
909 returns True) use line buffering. Other text files use the policy 908 returns ``True``) use line buffering. Other text files use the policy
910 described above for binary files. 909 described above for binary files.
911 910
912 *encoding* is the name of the encoding used to decode or encode the file. 911 *encoding* is the name of the encoding used to decode or encode the file.
913 This should only be used in text mode. The default encoding is platform 912 This should only be used in text mode. The default encoding is platform
914 dependent (whatever :func:`locale.getpreferredencoding` returns), but any 913 dependent (whatever :func:`locale.getpreferredencoding` returns), but any
915 encoding supported by Python can be used. See the :mod:`codecs` module for 914 encoding supported by Python can be used. See the :mod:`codecs` module for
916 the list of supported encodings. 915 the list of supported encodings.
917 916
918 *errors* is an optional string that specifies how encoding and decoding 917 *errors* is an optional string that specifies how encoding and decoding
919 errors are to be handled--this cannot be used in binary mode. 918 errors are to be handled--this cannot be used in binary mode.
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 1020
1022 .. versionchanged:: 3.3 1021 .. versionchanged:: 3.3
1023 The *opener* parameter was added. 1022 The *opener* parameter was added.
1024 The ``'x'`` mode was added. 1023 The ``'x'`` mode was added.
1025 :exc:`IOError` used to be raised, it is now an alias of :exc:`OSError`. 1024 :exc:`IOError` used to be raised, it is now an alias of :exc:`OSError`.
1026 :exc:`FileExistsError` is now raised if the file opened in exclusive 1025 :exc:`FileExistsError` is now raised if the file opened in exclusive
1027 creation mode (``'x'``) already exists. 1026 creation mode (``'x'``) already exists.
1028 1027
1029 .. versionchanged:: 3.4 1028 .. versionchanged:: 3.4
1030 The file is now non-inheritable. 1029 The file is now non-inheritable.
1030
1031 .. deprecated-removed:: 3.4 4.0
1032 The ``'U'`` mode.
1031 1033
1032 1034
1033 .. XXX works for bytes too, but should it? 1035 .. XXX works for bytes too, but should it?
1034 .. function:: ord(c) 1036 .. function:: ord(c)
1035 1037
1036 Given a string representing one Unicode character, return an integer 1038 Given a string representing one Unicode character, return an integer
1037 representing the Unicode code 1039 representing the Unicode code
1038 point of that character. For example, ``ord('a')`` returns the integer ``97` ` 1040 point of that character. For example, ``ord('a')`` returns the integer ``97` `
1039 and ``ord('\u2020')`` returns ``8224``. This is the inverse of :func:`chr`. 1041 and ``ord('\u2020')`` returns ``8224``. This is the inverse of :func:`chr`.
1040 1042
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
1525 .. versionchanged:: 3.3 1527 .. versionchanged:: 3.3
1526 Negative values for *level* are no longer supported (which also changes 1528 Negative values for *level* are no longer supported (which also changes
1527 the default value to 0). 1529 the default value to 0).
1528 1530
1529 1531
1530 .. rubric:: Footnotes 1532 .. rubric:: Footnotes
1531 1533
1532 .. [#] Note that the parser only accepts the Unix-style end of line convention. 1534 .. [#] Note that the parser only accepts the Unix-style end of line convention.
1533 If you are reading the code from a file, make sure to use newline conversion 1535 If you are reading the code from a file, make sure to use newline conversion
1534 mode to convert Windows or Mac-style newlines. 1536 mode to convert Windows or Mac-style newlines.
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+