mirror of
https://github.com/python/cpython.git
synced 2025-10-25 18:54:53 +00:00
Python 3.14.0rc3
This commit is contained in:
parent
a20395b899
commit
1c5b28405a
34 changed files with 595 additions and 265 deletions
|
|
@ -1,4 +1,4 @@
|
|||
# Autogenerated by Sphinx on Thu Aug 14 15:19:40 2025
|
||||
# Autogenerated by Sphinx on Thu Sep 18 09:45:33 2025
|
||||
# as part of the release process.
|
||||
|
||||
topics = {
|
||||
|
|
@ -634,6 +634,9 @@ class instances.
|
|||
Customizing module attribute access
|
||||
===================================
|
||||
|
||||
module.__getattr__()
|
||||
module.__dir__()
|
||||
|
||||
Special names "__getattr__" and "__dir__" can be also used to
|
||||
customize access to module attributes. The "__getattr__" function at
|
||||
the module level should accept one argument which is the name of an
|
||||
|
|
@ -649,6 +652,8 @@ class instances.
|
|||
present, this function overrides the standard "dir()" search on a
|
||||
module.
|
||||
|
||||
module.__class__
|
||||
|
||||
For a more fine grained customization of the module behavior (setting
|
||||
attributes, properties, etc.), one can set the "__class__" attribute
|
||||
of a module object to a subclass of "types.ModuleType". For example:
|
||||
|
|
@ -1093,12 +1098,33 @@ class and instance attributes applies as for regular assignments.
|
|||
'bltin-ellipsis-object': r'''The Ellipsis Object
|
||||
*******************
|
||||
|
||||
This object is commonly used by slicing (see Slicings). It supports
|
||||
no special operations. There is exactly one ellipsis object, named
|
||||
"Ellipsis" (a built-in name). "type(Ellipsis)()" produces the
|
||||
"Ellipsis" singleton.
|
||||
This object is commonly used used to indicate that something is
|
||||
omitted. It supports no special operations. There is exactly one
|
||||
ellipsis object, named "Ellipsis" (a built-in name).
|
||||
"type(Ellipsis)()" produces the "Ellipsis" singleton.
|
||||
|
||||
It is written as "Ellipsis" or "...".
|
||||
|
||||
In typical use, "..." as the "Ellipsis" object appears in a few
|
||||
different places, for instance:
|
||||
|
||||
* In type annotations, such as callable arguments or tuple elements.
|
||||
|
||||
* As the body of a function instead of a pass statement.
|
||||
|
||||
* In third-party libraries, such as Numpy’s slicing and striding.
|
||||
|
||||
Python also uses three dots in ways that are not "Ellipsis" objects,
|
||||
for instance:
|
||||
|
||||
* Doctest’s "ELLIPSIS", as a pattern for missing content.
|
||||
|
||||
* The default Python prompt of the *interactive* shell when partial
|
||||
input is incomplete.
|
||||
|
||||
Lastly, the Python documentation often uses three dots in conventional
|
||||
English usage to mean omitted content, even in code examples that also
|
||||
use them as the "Ellipsis".
|
||||
''',
|
||||
'bltin-null-object': r'''The Null Object
|
||||
***************
|
||||
|
|
@ -1968,7 +1994,8 @@ class attributes; they are shared by instances. Instance attributes
|
|||
group types, because that would have ambiguous semantics.
|
||||
|
||||
It is not possible to mix "except" and "except*" in the same "try".
|
||||
"break", "continue" and "return" cannot appear in an "except*" clause.
|
||||
The "break", "continue", and "return" statements cannot appear in an
|
||||
"except*" clause.
|
||||
|
||||
|
||||
"else" clause
|
||||
|
|
@ -1984,11 +2011,11 @@ class attributes; they are shared by instances. Instance attributes
|
|||
----------------
|
||||
|
||||
If "finally" is present, it specifies a ‘cleanup’ handler. The "try"
|
||||
clause is executed, including any "except" and "else" clauses. If an
|
||||
clause is executed, including any "except" and "else" clauses. If an
|
||||
exception occurs in any of the clauses and is not handled, the
|
||||
exception is temporarily saved. The "finally" clause is executed. If
|
||||
there is a saved exception it is re-raised at the end of the "finally"
|
||||
clause. If the "finally" clause raises another exception, the saved
|
||||
clause. If the "finally" clause raises another exception, the saved
|
||||
exception is set as the context of the new exception. If the "finally"
|
||||
clause executes a "return", "break" or "continue" statement, the saved
|
||||
exception is discarded. For example, this function returns 42.
|
||||
|
|
@ -2143,9 +2170,9 @@ def foo():
|
|||
The match statement is used for pattern matching. Syntax:
|
||||
|
||||
match_stmt: 'match' subject_expr ":" NEWLINE INDENT case_block+ DEDENT
|
||||
subject_expr: star_named_expression "," star_named_expressions?
|
||||
| named_expression
|
||||
case_block: 'case' patterns [guard] ":" block
|
||||
subject_expr: `!star_named_expression` "," `!star_named_expressions`?
|
||||
| `!named_expression`
|
||||
case_block: 'case' patterns [guard] ":" `!block`
|
||||
|
||||
Note:
|
||||
|
||||
|
|
@ -2236,7 +2263,7 @@ def foo():
|
|||
Guards
|
||||
------
|
||||
|
||||
guard: "if" named_expression
|
||||
guard: "if" `!named_expression`
|
||||
|
||||
A "guard" (which is part of the "case") must succeed for code inside
|
||||
the "case" block to execute. It takes the form: "if" followed by an
|
||||
|
|
@ -2530,7 +2557,7 @@ def foo():
|
|||
Note:
|
||||
|
||||
The length of the subject sequence is obtained via "len()" (i.e.
|
||||
via the "__len__()" protocol). This length may be cached by the
|
||||
via the "__len__()" protocol). This length may be cached by the
|
||||
interpreter in a similar manner as value patterns.
|
||||
|
||||
In simple terms "[P1, P2, P3," … ", P<N>]" matches only if all the
|
||||
|
|
@ -4644,8 +4671,8 @@ def inner(x):
|
|||
|
||||
Deletion of a name removes the binding of that name from the local or
|
||||
global namespace, depending on whether the name occurs in a "global"
|
||||
statement in the same code block. If the name is unbound, a
|
||||
"NameError" exception will be raised.
|
||||
statement in the same code block. Trying to delete an unbound name
|
||||
raises a "NameError" exception.
|
||||
|
||||
Deletion of attribute references, subscriptions and slicings is passed
|
||||
to the primary object involved; deletion of a slicing is in general
|
||||
|
|
@ -5282,7 +5309,7 @@ class of the instance or a *non-virtual base class* thereof. The
|
|||
subclasses can define their own format string syntax). The syntax is
|
||||
related to that of formatted string literals and template string
|
||||
literals, but it is less sophisticated and, in particular, does not
|
||||
support arbitrary expressions.
|
||||
support arbitrary expressions in interpolations.
|
||||
|
||||
Format strings contain “replacement fields” surrounded by curly braces
|
||||
"{}". Anything that is not contained in braces is considered literal
|
||||
|
|
@ -7640,21 +7667,24 @@ class C: pass # a class with no methods (yet)
|
|||
The "collections.abc" module provides a "MutableMapping" *abstract
|
||||
base class* to help create those methods from a base set of
|
||||
"__getitem__()", "__setitem__()", "__delitem__()", and "keys()".
|
||||
Mutable sequences should provide methods "append()", "count()",
|
||||
"index()", "extend()", "insert()", "pop()", "remove()", "reverse()"
|
||||
and "sort()", like Python standard "list" objects. Finally, sequence
|
||||
|
||||
Mutable sequences should provide methods "append()", "clear()",
|
||||
"count()", "extend()", "index()", "insert()", "pop()", "remove()", and
|
||||
"reverse()", like Python standard "list" objects. Finally, sequence
|
||||
types should implement addition (meaning concatenation) and
|
||||
multiplication (meaning repetition) by defining the methods
|
||||
"__add__()", "__radd__()", "__iadd__()", "__mul__()", "__rmul__()" and
|
||||
"__imul__()" described below; they should not define other numerical
|
||||
operators. It is recommended that both mappings and sequences
|
||||
implement the "__contains__()" method to allow efficient use of the
|
||||
"in" operator; for mappings, "in" should search the mapping’s keys;
|
||||
for sequences, it should search through the values. It is further
|
||||
recommended that both mappings and sequences implement the
|
||||
"__iter__()" method to allow efficient iteration through the
|
||||
container; for mappings, "__iter__()" should iterate through the
|
||||
object’s keys; for sequences, it should iterate through the values.
|
||||
operators.
|
||||
|
||||
It is recommended that both mappings and sequences implement the
|
||||
"__contains__()" method to allow efficient use of the "in" operator;
|
||||
for mappings, "in" should search the mapping’s keys; for sequences, it
|
||||
should search through the values. It is further recommended that both
|
||||
mappings and sequences implement the "__iter__()" method to allow
|
||||
efficient iteration through the container; for mappings, "__iter__()"
|
||||
should iterate through the object’s keys; for sequences, it should
|
||||
iterate through the values.
|
||||
|
||||
object.__len__(self)
|
||||
|
||||
|
|
@ -7891,8 +7921,8 @@ class C: pass # a class with no methods (yet)
|
|||
important that the emulation only be implemented to the degree that it
|
||||
makes sense for the object being modelled. For example, some
|
||||
sequences may work well with retrieval of individual elements, but
|
||||
extracting a slice may not make sense. (One example of this is the
|
||||
"NodeList" interface in the W3C’s Document Object Model.)
|
||||
extracting a slice may not make sense. (One example of this is the
|
||||
NodeList interface in the W3C’s Document Object Model.)
|
||||
|
||||
|
||||
Basic customization
|
||||
|
|
@ -8287,6 +8317,9 @@ class instances.
|
|||
Customizing module attribute access
|
||||
-----------------------------------
|
||||
|
||||
module.__getattr__()
|
||||
module.__dir__()
|
||||
|
||||
Special names "__getattr__" and "__dir__" can be also used to
|
||||
customize access to module attributes. The "__getattr__" function at
|
||||
the module level should accept one argument which is the name of an
|
||||
|
|
@ -8302,6 +8335,8 @@ class instances.
|
|||
present, this function overrides the standard "dir()" search on a
|
||||
module.
|
||||
|
||||
module.__class__
|
||||
|
||||
For a more fine grained customization of the module behavior (setting
|
||||
attributes, properties, etc.), one can set the "__class__" attribute
|
||||
of a module object to a subclass of "types.ModuleType". For example:
|
||||
|
|
@ -8997,21 +9032,24 @@ class of a class is known as that class’s *metaclass*, and most
|
|||
The "collections.abc" module provides a "MutableMapping" *abstract
|
||||
base class* to help create those methods from a base set of
|
||||
"__getitem__()", "__setitem__()", "__delitem__()", and "keys()".
|
||||
Mutable sequences should provide methods "append()", "count()",
|
||||
"index()", "extend()", "insert()", "pop()", "remove()", "reverse()"
|
||||
and "sort()", like Python standard "list" objects. Finally, sequence
|
||||
|
||||
Mutable sequences should provide methods "append()", "clear()",
|
||||
"count()", "extend()", "index()", "insert()", "pop()", "remove()", and
|
||||
"reverse()", like Python standard "list" objects. Finally, sequence
|
||||
types should implement addition (meaning concatenation) and
|
||||
multiplication (meaning repetition) by defining the methods
|
||||
"__add__()", "__radd__()", "__iadd__()", "__mul__()", "__rmul__()" and
|
||||
"__imul__()" described below; they should not define other numerical
|
||||
operators. It is recommended that both mappings and sequences
|
||||
implement the "__contains__()" method to allow efficient use of the
|
||||
"in" operator; for mappings, "in" should search the mapping’s keys;
|
||||
for sequences, it should search through the values. It is further
|
||||
recommended that both mappings and sequences implement the
|
||||
"__iter__()" method to allow efficient iteration through the
|
||||
container; for mappings, "__iter__()" should iterate through the
|
||||
object’s keys; for sequences, it should iterate through the values.
|
||||
operators.
|
||||
|
||||
It is recommended that both mappings and sequences implement the
|
||||
"__contains__()" method to allow efficient use of the "in" operator;
|
||||
for mappings, "in" should search the mapping’s keys; for sequences, it
|
||||
should search through the values. It is further recommended that both
|
||||
mappings and sequences implement the "__iter__()" method to allow
|
||||
efficient iteration through the container; for mappings, "__iter__()"
|
||||
should iterate through the object’s keys; for sequences, it should
|
||||
iterate through the values.
|
||||
|
||||
object.__len__(self)
|
||||
|
||||
|
|
@ -9567,7 +9605,7 @@ class is used in a class pattern with positional arguments, each
|
|||
|
||||
Added in version 3.3.
|
||||
|
||||
str.center(width[, fillchar])
|
||||
str.center(width, fillchar=' ', /)
|
||||
|
||||
Return centered in a string of length *width*. Padding is done
|
||||
using the specified *fillchar* (default is an ASCII space). The
|
||||
|
|
@ -9678,7 +9716,14 @@ class is used in a class pattern with positional arguments, each
|
|||
Return the lowest index in the string where substring *sub* is
|
||||
found within the slice "s[start:end]". Optional arguments *start*
|
||||
and *end* are interpreted as in slice notation. Return "-1" if
|
||||
*sub* is not found.
|
||||
*sub* is not found. For example:
|
||||
|
||||
>>> 'spam, spam, spam'.find('sp')
|
||||
0
|
||||
>>> 'spam, spam, spam'.find('sp', 5)
|
||||
6
|
||||
|
||||
See also "rfind()" and "index()".
|
||||
|
||||
Note:
|
||||
|
||||
|
|
@ -9864,14 +9909,14 @@ class is used in a class pattern with positional arguments, each
|
|||
>>> ' '.isupper()
|
||||
False
|
||||
|
||||
str.join(iterable)
|
||||
str.join(iterable, /)
|
||||
|
||||
Return a string which is the concatenation of the strings in
|
||||
*iterable*. A "TypeError" will be raised if there are any non-
|
||||
string values in *iterable*, including "bytes" objects. The
|
||||
separator between elements is the string providing this method.
|
||||
|
||||
str.ljust(width[, fillchar])
|
||||
str.ljust(width, fillchar=' ', /)
|
||||
|
||||
Return the string left justified in a string of length *width*.
|
||||
Padding is done using the specified *fillchar* (default is an ASCII
|
||||
|
|
@ -9886,7 +9931,7 @@ class is used in a class pattern with positional arguments, each
|
|||
The lowercasing algorithm used is described in section 3.13
|
||||
‘Default Case Folding’ of the Unicode Standard.
|
||||
|
||||
str.lstrip([chars])
|
||||
str.lstrip(chars=None, /)
|
||||
|
||||
Return a copy of the string with leading characters removed. The
|
||||
*chars* argument is a string specifying the set of characters to be
|
||||
|
|
@ -9907,7 +9952,8 @@ class is used in a class pattern with positional arguments, each
|
|||
>>> 'Arthur: three!'.removeprefix('Arthur: ')
|
||||
'three!'
|
||||
|
||||
static str.maketrans(x[, y[, z]])
|
||||
static str.maketrans(dict, /)
|
||||
static str.maketrans(from, to, remove='', /)
|
||||
|
||||
This static method returns a translation table usable for
|
||||
"str.translate()".
|
||||
|
|
@ -9918,12 +9964,12 @@ class is used in a class pattern with positional arguments, each
|
|||
Character keys will then be converted to ordinals.
|
||||
|
||||
If there are two arguments, they must be strings of equal length,
|
||||
and in the resulting dictionary, each character in x will be mapped
|
||||
to the character at the same position in y. If there is a third
|
||||
argument, it must be a string, whose characters will be mapped to
|
||||
"None" in the result.
|
||||
and in the resulting dictionary, each character in *from* will be
|
||||
mapped to the character at the same position in *to*. If there is
|
||||
a third argument, it must be a string, whose characters will be
|
||||
mapped to "None" in the result.
|
||||
|
||||
str.partition(sep)
|
||||
str.partition(sep, /)
|
||||
|
||||
Split the string at the first occurrence of *sep*, and return a
|
||||
3-tuple containing the part before the separator, the separator
|
||||
|
|
@ -9957,7 +10003,7 @@ class is used in a class pattern with positional arguments, each
|
|||
|
||||
Added in version 3.9.
|
||||
|
||||
str.replace(old, new, count=-1)
|
||||
str.replace(old, new, /, count=-1)
|
||||
|
||||
Return a copy of the string with all occurrences of substring *old*
|
||||
replaced by *new*. If *count* is given, only the first *count*
|
||||
|
|
@ -9979,14 +10025,14 @@ class is used in a class pattern with positional arguments, each
|
|||
Like "rfind()" but raises "ValueError" when the substring *sub* is
|
||||
not found.
|
||||
|
||||
str.rjust(width[, fillchar])
|
||||
str.rjust(width, fillchar=' ', /)
|
||||
|
||||
Return the string right justified in a string of length *width*.
|
||||
Padding is done using the specified *fillchar* (default is an ASCII
|
||||
space). The original string is returned if *width* is less than or
|
||||
equal to "len(s)".
|
||||
|
||||
str.rpartition(sep)
|
||||
str.rpartition(sep, /)
|
||||
|
||||
Split the string at the last occurrence of *sep*, and return a
|
||||
3-tuple containing the part before the separator, the separator
|
||||
|
|
@ -10003,7 +10049,7 @@ class is used in a class pattern with positional arguments, each
|
|||
from the right, "rsplit()" behaves like "split()" which is
|
||||
described in detail below.
|
||||
|
||||
str.rstrip([chars])
|
||||
str.rstrip(chars=None, /)
|
||||
|
||||
Return a copy of the string with trailing characters removed. The
|
||||
*chars* argument is a string specifying the set of characters to be
|
||||
|
|
@ -10146,7 +10192,7 @@ class is used in a class pattern with positional arguments, each
|
|||
With optional *start*, test string beginning at that position.
|
||||
With optional *end*, stop comparing string at that position.
|
||||
|
||||
str.strip([chars])
|
||||
str.strip(chars=None, /)
|
||||
|
||||
Return a copy of the string with the leading and trailing
|
||||
characters removed. The *chars* argument is a string specifying the
|
||||
|
|
@ -10210,7 +10256,7 @@ class is used in a class pattern with positional arguments, each
|
|||
>>> titlecase("they're bill's friends.")
|
||||
"They're Bill's Friends."
|
||||
|
||||
str.translate(table)
|
||||
str.translate(table, /)
|
||||
|
||||
Return a copy of the string in which each character has been mapped
|
||||
through the given translation table. The table must be an object
|
||||
|
|
@ -10238,7 +10284,7 @@ class is used in a class pattern with positional arguments, each
|
|||
The uppercasing algorithm used is described in section 3.13
|
||||
‘Default Case Folding’ of the Unicode Standard.
|
||||
|
||||
str.zfill(width)
|
||||
str.zfill(width, /)
|
||||
|
||||
Return a copy of the string left filled with ASCII "'0'" digits to
|
||||
make a string of length *width*. A leading sign prefix
|
||||
|
|
@ -10328,9 +10374,10 @@ class is used in a class pattern with positional arguments, each
|
|||
|
||||
See the linked sections for details on each type.
|
||||
|
||||
Prefixes are case-insensitive (for example, "B" works the same as
|
||||
"b"). The "r" prefix can be combined with "f", "t" or "b", so "fr",
|
||||
"rf", "tr", "rt", "br" and "rb" are also valid prefixes.
|
||||
Prefixes are case-insensitive (for example, ‘"B"’ works the same as
|
||||
‘"b"’). The ‘"r"’ prefix can be combined with ‘"f"’, ‘"t"’ or ‘"b"’,
|
||||
so ‘"fr"’, ‘"rf"’, ‘"tr"’, ‘"rt"’, ‘"br"’, and ‘"rb"’ are also valid
|
||||
prefixes.
|
||||
|
||||
Added in version 3.3: The "'rb'" prefix of raw bytes literals has been
|
||||
added as a synonym of "'br'".Support for the unicode legacy literal
|
||||
|
|
@ -10350,10 +10397,10 @@ class is used in a class pattern with positional arguments, each
|
|||
STRING: [stringprefix] (stringcontent)
|
||||
stringprefix: <("r" | "u" | "b" | "br" | "rb"), case-insensitive>
|
||||
stringcontent:
|
||||
| "'" ( !"'" stringitem)* "'"
|
||||
| '"' ( !'"' stringitem)* '"'
|
||||
| "\'\'\'" ( !"\'\'\'" longstringitem)* "\'\'\'"
|
||||
| '"""' ( !'"""' longstringitem)* '"""'
|
||||
| "'" ( !"'" stringitem)* "'"
|
||||
| '"' ( !'"' stringitem)* '"'
|
||||
stringitem: stringchar | stringescapeseq
|
||||
stringchar: <any source_character, except backslash and newline>
|
||||
longstringitem: stringitem | newline
|
||||
|
|
@ -10367,7 +10414,7 @@ class is used in a class pattern with positional arguments, each
|
|||
Escape sequences
|
||||
================
|
||||
|
||||
Unless an "'r'" or "'R'" prefix is present, escape sequences in string
|
||||
Unless an ‘"r"’ or ‘"R"’ prefix is present, escape sequences in string
|
||||
and bytes literals are interpreted according to rules similar to those
|
||||
used by Standard C. The recognized escape sequences are:
|
||||
|
||||
|
|
@ -10535,7 +10582,7 @@ class is used in a class pattern with positional arguments, each
|
|||
Bytes literals
|
||||
==============
|
||||
|
||||
*Bytes literals* are always prefixed with "'b'" or "'B'"; they produce
|
||||
*Bytes literals* are always prefixed with ‘"b"’ or ‘"B"’; they produce
|
||||
an instance of the "bytes" type instead of the "str" type. They may
|
||||
only contain ASCII characters; bytes with a numeric value of 128 or
|
||||
greater must be expressed with escape sequences (typically Hexadecimal
|
||||
|
|
@ -10554,7 +10601,7 @@ class is used in a class pattern with positional arguments, each
|
|||
===================
|
||||
|
||||
Both string and bytes literals may optionally be prefixed with a
|
||||
letter "'r'" or "'R'"; such constructs are called *raw string
|
||||
letter ‘"r"’ or ‘"R"’; such constructs are called *raw string
|
||||
literals* and *raw bytes literals* respectively and treat backslashes
|
||||
as literal characters. As a result, in raw string literals, escape
|
||||
sequences are not treated specially:
|
||||
|
|
@ -10579,7 +10626,7 @@ class is used in a class pattern with positional arguments, each
|
|||
Added in version 3.6.
|
||||
|
||||
A *formatted string literal* or *f-string* is a string literal that is
|
||||
prefixed with "f" or "F". These strings may contain replacement
|
||||
prefixed with ‘"f"’ or ‘"F"’. These strings may contain replacement
|
||||
fields, which are expressions delimited by curly braces "{}". While
|
||||
other string literals always have a constant value, formatted strings
|
||||
are really expressions evaluated at run time.
|
||||
|
|
@ -10736,12 +10783,12 @@ class is used in a class pattern with positional arguments, each
|
|||
Added in version 3.14.
|
||||
|
||||
A *template string literal* or *t-string* is a string literal that is
|
||||
prefixed with "t" or "T". These strings follow the same syntax and
|
||||
prefixed with ‘"t"’ or ‘"T"’. These strings follow the same syntax and
|
||||
evaluation rules as formatted string literals, with the following
|
||||
differences:
|
||||
|
||||
* Rather than evaluating to a "str" object, t-strings evaluate to a
|
||||
"Template" object from the "string.templatelib" module.
|
||||
* Rather than evaluating to a "str" object, template string literals
|
||||
evaluate to a "string.templatelib.Template" object.
|
||||
|
||||
* The "format()" protocol is not used. Instead, the format specifier
|
||||
and conversions (if any) are passed to a new "Interpolation" object
|
||||
|
|
@ -10752,20 +10799,18 @@ class is used in a class pattern with positional arguments, each
|
|||
* Format specifiers containing nested replacement fields are evaluated
|
||||
eagerly, prior to being passed to the "Interpolation" object. For
|
||||
instance, an interpolation of the form "{amount:.{precision}f}" will
|
||||
evaluate the expression "{precision}" before setting the
|
||||
"format_spec" attribute of the resulting "Interpolation" object; if
|
||||
"precision" is (for example) "2", the resulting format specifier
|
||||
will be "'.2f'".
|
||||
evaluate the inner expression "{precision}" to determine the value
|
||||
of the "format_spec" attribute. If "precision" were to be "2", the
|
||||
resulting format specifier would be "'.2f'".
|
||||
|
||||
* When the equal sign "'='" is provided in an interpolation
|
||||
expression, the resulting "Template" object will have the expression
|
||||
text along with a "'='" character placed in its "strings" attribute.
|
||||
The "interpolations" attribute will also contain an "Interpolation"
|
||||
instance for the expression. By default, the "conversion" attribute
|
||||
will be set to "'r'" (that is, "repr()"), unless there is a
|
||||
conversion explicitly specified (in which case it overrides the
|
||||
default) or a format specifier is provided (in which case, the
|
||||
"conversion" defaults to "None").
|
||||
* When the equals sign "'='" is provided in an interpolation
|
||||
expression, the text of the expression is appended to the literal
|
||||
string that precedes the relevant interpolation. This includes the
|
||||
equals sign and any surrounding whitespace. The "Interpolation"
|
||||
instance for the expression will be created as normal, except that
|
||||
"conversion" will be set to ‘"r"’ ("repr()") by default. If an
|
||||
explicit conversion or format specifier are provided, this will
|
||||
override the default behaviour.
|
||||
''',
|
||||
'subscriptions': r'''Subscriptions
|
||||
*************
|
||||
|
|
@ -11008,7 +11053,8 @@ class is used in a class pattern with positional arguments, each
|
|||
group types, because that would have ambiguous semantics.
|
||||
|
||||
It is not possible to mix "except" and "except*" in the same "try".
|
||||
"break", "continue" and "return" cannot appear in an "except*" clause.
|
||||
The "break", "continue", and "return" statements cannot appear in an
|
||||
"except*" clause.
|
||||
|
||||
|
||||
"else" clause
|
||||
|
|
@ -11024,11 +11070,11 @@ class is used in a class pattern with positional arguments, each
|
|||
================
|
||||
|
||||
If "finally" is present, it specifies a ‘cleanup’ handler. The "try"
|
||||
clause is executed, including any "except" and "else" clauses. If an
|
||||
clause is executed, including any "except" and "else" clauses. If an
|
||||
exception occurs in any of the clauses and is not handled, the
|
||||
exception is temporarily saved. The "finally" clause is executed. If
|
||||
there is a saved exception it is re-raised at the end of the "finally"
|
||||
clause. If the "finally" clause raises another exception, the saved
|
||||
clause. If the "finally" clause raises another exception, the saved
|
||||
exception is set as the context of the new exception. If the "finally"
|
||||
clause executes a "return", "break" or "continue" statement, the saved
|
||||
exception is discarded. For example, this function returns 42.
|
||||
|
|
@ -11316,7 +11362,7 @@ def foo():
|
|||
Sets
|
||||
These represent a mutable set. They are created by the built-in
|
||||
"set()" constructor and can be modified afterwards by several
|
||||
methods, such as "add()".
|
||||
methods, such as "add".
|
||||
|
||||
Frozen sets
|
||||
These represent an immutable set. They are created by the built-in
|
||||
|
|
@ -12261,6 +12307,10 @@ class instance has a namespace implemented as a dictionary which is
|
|||
| | (this is an index into the *bytecode* string of |
|
||||
| | the code object) |
|
||||
+----------------------------------------------------+----------------------------------------------------+
|
||||
| frame.f_generator | The *generator* or *coroutine* object that owns |
|
||||
| | this frame, or "None" if the frame is a normal |
|
||||
| | function. Added in version 3.14. |
|
||||
+----------------------------------------------------+----------------------------------------------------+
|
||||
|
||||
|
||||
Special writable attributes
|
||||
|
|
@ -12441,8 +12491,8 @@ class instance has a namespace implemented as a dictionary which is
|
|||
dictionary entry.
|
||||
|
||||
class dict(**kwargs)
|
||||
class dict(mapping, **kwargs)
|
||||
class dict(iterable, **kwargs)
|
||||
class dict(mapping, /, **kwargs)
|
||||
class dict(iterable, /, **kwargs)
|
||||
|
||||
Return a new dictionary initialized from an optional positional
|
||||
argument and a possibly empty set of keyword arguments.
|
||||
|
|
@ -12558,8 +12608,8 @@ class dict(iterable, **kwargs)
|
|||
1
|
||||
|
||||
The example above shows part of the implementation of
|
||||
"collections.Counter". A different "__missing__" method is used
|
||||
by "collections.defaultdict".
|
||||
"collections.Counter". A different "__missing__()" method is
|
||||
used by "collections.defaultdict".
|
||||
|
||||
d[key] = value
|
||||
|
||||
|
|
@ -12618,7 +12668,8 @@ class dict(iterable, **kwargs)
|
|||
Return a new view of the dictionary’s keys. See the
|
||||
documentation of view objects.
|
||||
|
||||
pop(key[, default])
|
||||
pop(key, /)
|
||||
pop(key, default, /)
|
||||
|
||||
If *key* is in the dictionary, remove it and return its value,
|
||||
else return *default*. If *default* is not given and *key* is
|
||||
|
|
@ -12649,10 +12700,13 @@ class dict(iterable, **kwargs)
|
|||
*key* with a value of *default* and return *default*. *default*
|
||||
defaults to "None".
|
||||
|
||||
update([other])
|
||||
update(**kwargs)
|
||||
update(mapping, /, **kwargs)
|
||||
update(iterable, /, **kwargs)
|
||||
|
||||
Update the dictionary with the key/value pairs from *other*,
|
||||
overwriting existing keys. Return "None".
|
||||
Update the dictionary with the key/value pairs from *mapping* or
|
||||
*iterable* and *kwargs*, overwriting existing keys. Return
|
||||
"None".
|
||||
|
||||
"update()" accepts either another object with a "keys()" method
|
||||
(in which case "__getitem__()" is called with every key returned
|
||||
|
|
@ -12917,7 +12971,7 @@ class dict(iterable, **kwargs)
|
|||
| "s * n" or "n * s" | equivalent to adding *s* to | (2)(7) |
|
||||
| | itself *n* times | |
|
||||
+----------------------------+----------------------------------+------------+
|
||||
| "s[i]" | *i*th item of *s*, origin 0 | (3)(9) |
|
||||
| "s[i]" | *i*th item of *s*, origin 0 | (3)(8) |
|
||||
+----------------------------+----------------------------------+------------+
|
||||
| "s[i:j]" | slice of *s* from *i* to *j* | (3)(4) |
|
||||
+----------------------------+----------------------------------+------------+
|
||||
|
|
@ -12930,13 +12984,6 @@ class dict(iterable, **kwargs)
|
|||
+----------------------------+----------------------------------+------------+
|
||||
| "max(s)" | largest item of *s* | |
|
||||
+----------------------------+----------------------------------+------------+
|
||||
| "s.index(x[, i[, j]])" | index of the first occurrence of | (8) |
|
||||
| | *x* in *s* (at or after index | |
|
||||
| | *i* and before index *j*) | |
|
||||
+----------------------------+----------------------------------+------------+
|
||||
| "s.count(x)" | total number of occurrences of | |
|
||||
| | *x* in *s* | |
|
||||
+----------------------------+----------------------------------+------------+
|
||||
|
||||
Sequences of the same type also support comparisons. In particular,
|
||||
tuples and lists are compared lexicographically by comparing
|
||||
|
|
@ -13033,15 +13080,31 @@ class dict(iterable, **kwargs)
|
|||
that follow specific patterns, and hence don’t support sequence
|
||||
concatenation or repetition.
|
||||
|
||||
8. "index" raises "ValueError" when *x* is not found in *s*. Not all
|
||||
implementations support passing the additional arguments *i* and
|
||||
*j*. These arguments allow efficient searching of subsections of
|
||||
the sequence. Passing the extra arguments is roughly equivalent to
|
||||
using "s[i:j].index(x)", only without copying any data and with the
|
||||
returned index being relative to the start of the sequence rather
|
||||
than the start of the slice.
|
||||
8. An "IndexError" is raised if *i* is outside the sequence range.
|
||||
|
||||
9. An "IndexError" is raised if *i* is outside the sequence range.
|
||||
-[ Sequence Methods ]-
|
||||
|
||||
Sequence types also support the following methods:
|
||||
|
||||
sequence.count(value, /)
|
||||
|
||||
Return the total number of occurrences of *value* in *sequence*.
|
||||
|
||||
sequence.index(value[, start[, stop])
|
||||
|
||||
Return the index of the first occurrence of *value* in *sequence*.
|
||||
|
||||
Raises "ValueError" if *value* is not found in *sequence*.
|
||||
|
||||
The *start* or *stop* arguments allow for efficient searching of
|
||||
subsections of the sequence, beginning at *start* and ending at
|
||||
*stop*. This is roughly equivalent to "start +
|
||||
sequence[start:stop].index(value)", only without copying any data.
|
||||
|
||||
Caution:
|
||||
|
||||
Not all sequence types support passing the *start* and *stop*
|
||||
arguments.
|
||||
|
||||
|
||||
Immutable Sequence Types
|
||||
|
|
@ -13093,64 +13156,80 @@ class dict(iterable, **kwargs)
|
|||
| "del s[i:j:k]" | removes the elements of | |
|
||||
| | "s[i:j:k]" from the list | |
|
||||
+--------------------------------+----------------------------------+-----------------------+
|
||||
| "s.append(x)" | appends *x* to the end of the | |
|
||||
| | sequence (same as | |
|
||||
| | "s[len(s):len(s)] = [x]") | |
|
||||
+--------------------------------+----------------------------------+-----------------------+
|
||||
| "s.clear()" | removes all items from *s* (same | (5) |
|
||||
| | as "del s[:]") | |
|
||||
+--------------------------------+----------------------------------+-----------------------+
|
||||
| "s.copy()" | creates a shallow copy of *s* | (5) |
|
||||
| | (same as "s[:]") | |
|
||||
+--------------------------------+----------------------------------+-----------------------+
|
||||
| "s.extend(t)" or "s += t" | extends *s* with the contents of | |
|
||||
| "s += t" | extends *s* with the contents of | |
|
||||
| | *t* (for the most part the same | |
|
||||
| | as "s[len(s):len(s)] = t") | |
|
||||
+--------------------------------+----------------------------------+-----------------------+
|
||||
| "s *= n" | updates *s* with its contents | (6) |
|
||||
| "s *= n" | updates *s* with its contents | (2) |
|
||||
| | repeated *n* times | |
|
||||
+--------------------------------+----------------------------------+-----------------------+
|
||||
| "s.insert(i, x)" | inserts *x* into *s* at the | |
|
||||
| | index given by *i* (same as | |
|
||||
| | "s[i:i] = [x]") | |
|
||||
+--------------------------------+----------------------------------+-----------------------+
|
||||
| "s.pop()" or "s.pop(i)" | retrieves the item at *i* and | (2) |
|
||||
| | also removes it from *s* | |
|
||||
+--------------------------------+----------------------------------+-----------------------+
|
||||
| "s.remove(x)" | removes the first item from *s* | (3) |
|
||||
| | where "s[i]" is equal to *x* | |
|
||||
+--------------------------------+----------------------------------+-----------------------+
|
||||
| "s.reverse()" | reverses the items of *s* in | (4) |
|
||||
| | place | |
|
||||
+--------------------------------+----------------------------------+-----------------------+
|
||||
|
||||
Notes:
|
||||
|
||||
1. If *k* is not equal to "1", *t* must have the same length as the
|
||||
slice it is replacing.
|
||||
|
||||
2. The optional argument *i* defaults to "-1", so that by default the
|
||||
last item is removed and returned.
|
||||
|
||||
3. "remove()" raises "ValueError" when *x* is not found in *s*.
|
||||
|
||||
4. The "reverse()" method modifies the sequence in place for economy
|
||||
of space when reversing a large sequence. To remind users that it
|
||||
operates by side effect, it does not return the reversed sequence.
|
||||
|
||||
5. "clear()" and "copy()" are included for consistency with the
|
||||
interfaces of mutable containers that don’t support slicing
|
||||
operations (such as "dict" and "set"). "copy()" is not part of the
|
||||
"collections.abc.MutableSequence" ABC, but most concrete mutable
|
||||
sequence classes provide it.
|
||||
|
||||
Added in version 3.3: "clear()" and "copy()" methods.
|
||||
|
||||
6. The value *n* is an integer, or an object implementing
|
||||
2. The value *n* is an integer, or an object implementing
|
||||
"__index__()". Zero and negative values of *n* clear the sequence.
|
||||
Items in the sequence are not copied; they are referenced multiple
|
||||
times, as explained for "s * n" under Common Sequence Operations.
|
||||
|
||||
-[ Mutable Sequence Methods ]-
|
||||
|
||||
Mutable sequence types also support the following methods:
|
||||
|
||||
sequence.append(value, /)
|
||||
|
||||
Append *value* to the end of the sequence This is equivalent to
|
||||
writing "seq[len(seq):len(seq)] = [value]".
|
||||
|
||||
sequence.clear()
|
||||
|
||||
Added in version 3.3.
|
||||
|
||||
Remove all items from *sequence*. This is equivalent to writing
|
||||
"del sequence[:]".
|
||||
|
||||
sequence.copy()
|
||||
|
||||
Added in version 3.3.
|
||||
|
||||
Create a shallow copy of *sequence*. This is equivalent to writing
|
||||
"sequence[:]".
|
||||
|
||||
Hint:
|
||||
|
||||
The "copy()" method is not part of the "MutableSequence" "ABC",
|
||||
but most concrete mutable sequence types provide it.
|
||||
|
||||
sequence.extend(iterable, /)
|
||||
|
||||
Extend *sequence* with the contents of *iterable*. For the most
|
||||
part, this is the same as writing "seq[len(seq):len(seq)] =
|
||||
iterable".
|
||||
|
||||
sequence.insert(index, value, /)
|
||||
|
||||
Insert *value* into *sequence* at the given *index*. This is
|
||||
equivalent to writing "sequence[index:index] = [value]".
|
||||
|
||||
sequence.pop(index=-1, /)
|
||||
|
||||
Retrieve the item at *index* and also removes it from *sequence*.
|
||||
By default, the last item in *sequence* is removed and returned.
|
||||
|
||||
sequence.remove(value, /)
|
||||
|
||||
Remove the first item from *sequence* where "sequence[i] == value".
|
||||
|
||||
Raises "ValueError" if *value* is not found in *sequence*.
|
||||
|
||||
sequence.reverse()
|
||||
|
||||
Reverse the items of *sequence* in place. This method maintains
|
||||
economy of space when reversing a large sequence. To remind users
|
||||
that it operates by side-effect, it returns "None".
|
||||
|
||||
|
||||
Lists
|
||||
=====
|
||||
|
|
@ -13159,7 +13238,7 @@ class dict(iterable, **kwargs)
|
|||
homogeneous items (where the precise degree of similarity will vary by
|
||||
application).
|
||||
|
||||
class list([iterable])
|
||||
class list(iterable=(), /)
|
||||
|
||||
Lists may be constructed in several ways:
|
||||
|
||||
|
|
@ -13240,7 +13319,7 @@ class list([iterable])
|
|||
of homogeneous data is needed (such as allowing storage in a "set" or
|
||||
"dict" instance).
|
||||
|
||||
class tuple([iterable])
|
||||
class tuple(iterable=(), /)
|
||||
|
||||
Tuples may be constructed in a number of ways:
|
||||
|
||||
|
|
@ -13280,8 +13359,8 @@ class tuple([iterable])
|
|||
The "range" type represents an immutable sequence of numbers and is
|
||||
commonly used for looping a specific number of times in "for" loops.
|
||||
|
||||
class range(stop)
|
||||
class range(start, stop[, step])
|
||||
class range(stop, /)
|
||||
class range(start, stop, step=1, /)
|
||||
|
||||
The arguments to the range constructor must be integers (either
|
||||
built-in "int" or any object that implements the "__index__()"
|
||||
|
|
@ -13425,63 +13504,79 @@ class range(start, stop[, step])
|
|||
| "del s[i:j:k]" | removes the elements of | |
|
||||
| | "s[i:j:k]" from the list | |
|
||||
+--------------------------------+----------------------------------+-----------------------+
|
||||
| "s.append(x)" | appends *x* to the end of the | |
|
||||
| | sequence (same as | |
|
||||
| | "s[len(s):len(s)] = [x]") | |
|
||||
+--------------------------------+----------------------------------+-----------------------+
|
||||
| "s.clear()" | removes all items from *s* (same | (5) |
|
||||
| | as "del s[:]") | |
|
||||
+--------------------------------+----------------------------------+-----------------------+
|
||||
| "s.copy()" | creates a shallow copy of *s* | (5) |
|
||||
| | (same as "s[:]") | |
|
||||
+--------------------------------+----------------------------------+-----------------------+
|
||||
| "s.extend(t)" or "s += t" | extends *s* with the contents of | |
|
||||
| "s += t" | extends *s* with the contents of | |
|
||||
| | *t* (for the most part the same | |
|
||||
| | as "s[len(s):len(s)] = t") | |
|
||||
+--------------------------------+----------------------------------+-----------------------+
|
||||
| "s *= n" | updates *s* with its contents | (6) |
|
||||
| "s *= n" | updates *s* with its contents | (2) |
|
||||
| | repeated *n* times | |
|
||||
+--------------------------------+----------------------------------+-----------------------+
|
||||
| "s.insert(i, x)" | inserts *x* into *s* at the | |
|
||||
| | index given by *i* (same as | |
|
||||
| | "s[i:i] = [x]") | |
|
||||
+--------------------------------+----------------------------------+-----------------------+
|
||||
| "s.pop()" or "s.pop(i)" | retrieves the item at *i* and | (2) |
|
||||
| | also removes it from *s* | |
|
||||
+--------------------------------+----------------------------------+-----------------------+
|
||||
| "s.remove(x)" | removes the first item from *s* | (3) |
|
||||
| | where "s[i]" is equal to *x* | |
|
||||
+--------------------------------+----------------------------------+-----------------------+
|
||||
| "s.reverse()" | reverses the items of *s* in | (4) |
|
||||
| | place | |
|
||||
+--------------------------------+----------------------------------+-----------------------+
|
||||
|
||||
Notes:
|
||||
|
||||
1. If *k* is not equal to "1", *t* must have the same length as the
|
||||
slice it is replacing.
|
||||
|
||||
2. The optional argument *i* defaults to "-1", so that by default the
|
||||
last item is removed and returned.
|
||||
|
||||
3. "remove()" raises "ValueError" when *x* is not found in *s*.
|
||||
|
||||
4. The "reverse()" method modifies the sequence in place for economy
|
||||
of space when reversing a large sequence. To remind users that it
|
||||
operates by side effect, it does not return the reversed sequence.
|
||||
|
||||
5. "clear()" and "copy()" are included for consistency with the
|
||||
interfaces of mutable containers that don’t support slicing
|
||||
operations (such as "dict" and "set"). "copy()" is not part of the
|
||||
"collections.abc.MutableSequence" ABC, but most concrete mutable
|
||||
sequence classes provide it.
|
||||
|
||||
Added in version 3.3: "clear()" and "copy()" methods.
|
||||
|
||||
6. The value *n* is an integer, or an object implementing
|
||||
2. The value *n* is an integer, or an object implementing
|
||||
"__index__()". Zero and negative values of *n* clear the sequence.
|
||||
Items in the sequence are not copied; they are referenced multiple
|
||||
times, as explained for "s * n" under Common Sequence Operations.
|
||||
|
||||
-[ Mutable Sequence Methods ]-
|
||||
|
||||
Mutable sequence types also support the following methods:
|
||||
|
||||
sequence.append(value, /)
|
||||
|
||||
Append *value* to the end of the sequence This is equivalent to
|
||||
writing "seq[len(seq):len(seq)] = [value]".
|
||||
|
||||
sequence.clear()
|
||||
|
||||
Added in version 3.3.
|
||||
|
||||
Remove all items from *sequence*. This is equivalent to writing
|
||||
"del sequence[:]".
|
||||
|
||||
sequence.copy()
|
||||
|
||||
Added in version 3.3.
|
||||
|
||||
Create a shallow copy of *sequence*. This is equivalent to writing
|
||||
"sequence[:]".
|
||||
|
||||
Hint:
|
||||
|
||||
The "copy()" method is not part of the "MutableSequence" "ABC",
|
||||
but most concrete mutable sequence types provide it.
|
||||
|
||||
sequence.extend(iterable, /)
|
||||
|
||||
Extend *sequence* with the contents of *iterable*. For the most
|
||||
part, this is the same as writing "seq[len(seq):len(seq)] =
|
||||
iterable".
|
||||
|
||||
sequence.insert(index, value, /)
|
||||
|
||||
Insert *value* into *sequence* at the given *index*. This is
|
||||
equivalent to writing "sequence[index:index] = [value]".
|
||||
|
||||
sequence.pop(index=-1, /)
|
||||
|
||||
Retrieve the item at *index* and also removes it from *sequence*.
|
||||
By default, the last item in *sequence* is removed and returned.
|
||||
|
||||
sequence.remove(value, /)
|
||||
|
||||
Remove the first item from *sequence* where "sequence[i] == value".
|
||||
|
||||
Raises "ValueError" if *value* is not found in *sequence*.
|
||||
|
||||
sequence.reverse()
|
||||
|
||||
Reverse the items of *sequence* in place. This method maintains
|
||||
economy of space when reversing a large sequence. To remind users
|
||||
that it operates by side-effect, it returns "None".
|
||||
''',
|
||||
'unary': r'''Unary arithmetic and bitwise operations
|
||||
***************************************
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue