chunk_id large_stringlengths 36 36 | doc_type large_stringclasses 2
values | category large_stringclasses 17
values | document large_stringclasses 50
values | version_raw large_stringclasses 590
values | chunk_index int64 0 262 | text large_stringlengths 11 5.69k | file_path large_stringclasses 882
values |
|---|---|---|---|---|---|---|---|
2f89e886-9d40-57a3-a64b-1d66024bcda3 | docs | python | python_datamodel | 310 | 108 | ### 3.3.6. Emulating callable objects[¶](#emulating-callable-objects "Permalink to this headline")
`object.``__call__`(*self*[, *args...*])[¶](#object.__call__ "Permalink to this definition")
: Called when the instance is “called” as a function; if this method is defined,
`x(arg1, arg2, ...)` roughly translates ... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
2b3a870d-e65b-5b68-8b1a-a8b9573e90fe | docs | python | python_datamodel | 310 | 109 | a sequence, the allowable keys should be the integers *k* for which `0 <= k <
N` where *N* is the length of the sequence, or [`slice`](../library/functions.html#slice "slice") objects, which define a
range of items. It is also recommended that mappings provide the methods
`keys()`, `values()`, `items()`, `get()`, `clea... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
e3211192-0fc2-5ec3-acf7-b41c3d4fb999 | docs | python | python_datamodel | 310 | 110 | [`__getitem__()`](#object.__getitem__ "object.__getitem__"), [`__setitem__()`](#object.__setitem__ "object.__setitem__"), [`__delitem__()`](#object.__delitem__ "object.__delitem__"), and `keys()`.
Mutable sequences should provide methods `append()`, `count()`,
`index()`, `extend()`, `insert()`, `pop()`, `remove()`,
`re... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
05f961f6-0d54-5706-883f-eee83fa96591 | docs | python | python_datamodel | 310 | 111 | [`__contains__()`](#object.__contains__ "object.__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__()`](#object.__it... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
f04c3d0c-9a89-59c1-81ac-58f7365580e4 | docs | python | python_datamodel | 310 | 112 | **CPython implementation detail:** In CPython, the length is required to be at most [`sys.maxsize`](../library/sys.html#sys.maxsize "sys.maxsize").
If the length is larger than `sys.maxsize` some features (such as
[`len()`](../library/functions.html#len "len")) may raise [`OverflowError`](../library/excepti... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
cc614a33-5986-59f6-a5da-6b5c1e649e7d | docs | python | python_datamodel | 310 | 113 | [`NotImplemented`](../library/constants.html#NotImplemented "NotImplemented"), which is treated the same as if the
`__length_hint__` method didn’t exist at all. This method is purely an
optimization and is never required for correctness.
New in version 3.4.
Note
Slicing is done exclusively with the f... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
2ab7f4de-b891-51a2-91b7-e3c014537fe8 | docs | python | python_datamodel | 310 | 114 | of an inappropriate type, [`TypeError`](../library/exceptions.html#TypeError "TypeError") may be raised; if of a value
outside the set of indexes for the sequence (after any special
interpretation of negative values), [`IndexError`](../library/exceptions.html#IndexError "IndexError") should be raised. For
... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
035161a8-2097-53bb-868c-0ddbd9e32a65 | docs | python | python_datamodel | 310 | 115 | `__getitem__()`. See [\_\_class\_getitem\_\_ versus \_\_getitem\_\_](#classgetitem-versus-getitem) for more
details.
`object.``__setitem__`(*self*, *key*, *value*)[¶](#object.__setitem__ "Permalink to this definition")
: Called to implement assignment to `self[key]`. Same note as for
[`__getitem__()`](#o... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
d557ad49-0d77-520e-a460-66fd33e48ca3 | docs | python | python_datamodel | 310 | 116 | objects support removal of keys, or for sequences if elements can be removed
from the sequence. The same exceptions should be raised for improper *key*
values as for the [`__getitem__()`](#object.__getitem__ "object.__getitem__") method.
`object.``__missing__`(*self*, *key*)[¶](#object.__missing__ "Permali... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
0d8936f8-0817-58ee-ad1a-250ffede63a8 | docs | python | python_datamodel | 310 | 117 | : Called (if present) by the [`reversed()`](../library/functions.html#reversed "reversed") built-in to implement
reverse iteration. It should return a new iterator object that iterates
over all the objects in the container in reverse order.
If the [`__reversed__()`](#object.__reversed__ "object.__reverse... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
46e68bd7-a229-5f17-aa1f-b386d6ab9d0c | docs | python | python_datamodel | 310 | 118 | implemented as an iteration through a container. However, container objects can
supply the following special method with a more efficient implementation, which
also does not require the object be iterable.
`object.``__contains__`(*self*, *item*)[¶](#object.__contains__ "Permalink to this definition")
: Called to imp... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
a0a41695-0866-5b0e-a472-aaf1e6ae9a95 | docs | python | python_datamodel | 310 | 119 | ### 3.3.8. Emulating numeric types[¶](#emulating-numeric-types "Permalink to this headline")
The following methods can be defined to emulate numeric objects. Methods
corresponding to operations that are not supported by the particular kind of
number implemented (e.g., bitwise operations for non-integral numbers) shoul... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
7e7c369d-cea0-5785-9402-f6b60e0da67b | docs | python | python_datamodel | 310 | 120 | `object.``__divmod__`(*self*, *other*)[¶](#object.__divmod__ "Permalink to this definition")
`object.``__pow__`(*self*, *other*[, *modulo*])[¶](#object.__pow__ "Permalink to this definition")
`object.``__lshift__`(*self*, *other*)[¶](#object.__lshift__ "Permalink to this definition")
`object.``__rshift__`(*self*, *o... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
2fc0af29-cd68-5154-a8fb-dff9a68c7b97 | docs | python | python_datamodel | 310 | 121 | has an [`__add__()`](#object.__add__ "object.__add__") method, `x.__add__(y)` is called. The
[`__divmod__()`](#object.__divmod__ "object.__divmod__") method should be the equivalent to using
[`__floordiv__()`](#object.__floordiv__ "object.__floordiv__") and [`__mod__()`](#object.__mod__ "object.__mod__"); i... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
a4dd1b44-b836-587a-8f06-5fd2a8d4a5ad | docs | python | python_datamodel | 310 | 122 | `object.``__rmul__`(*self*, *other*)[¶](#object.__rmul__ "Permalink to this definition")
`object.``__rmatmul__`(*self*, *other*)[¶](#object.__rmatmul__ "Permalink to this definition")
`object.``__rtruediv__`(*self*, *other*)[¶](#object.__rtruediv__ "Permalink to this definition")
`object.``__rfloordiv__`(*self*, *ot... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
3344e4f1-9c06-5fb1-8d7d-fce22169c775 | docs | python | python_datamodel | 310 | 123 | `object.``__rxor__`(*self*, *other*)[¶](#object.__rxor__ "Permalink to this definition")
`object.``__ror__`(*self*, *other*)[¶](#object.__ror__ "Permalink to this definition")
: These methods are called to implement the binary arithmetic operations
(`+`, `-`, `*`, `@`, `/`, `//`, `%`, [`divmod()`](../library/fun... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
b89d9aef-e938-58fb-a188-857a68c3a049 | docs | python | python_datamodel | 310 | 124 | coercion rules would become too complicated).
Note
If the right operand’s type is a subclass of the left operand’s type and
that subclass provides a different implementation of the reflected method
for the operation, this method will be called before the left operand’s
non-reflected method. Th... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
16a030cb-4625-5e70-9646-bb0148e0a3f7 | docs | python | python_datamodel | 310 | 125 | `object.``__imod__`(*self*, *other*)[¶](#object.__imod__ "Permalink to this definition")
`object.``__ipow__`(*self*, *other*[, *modulo*])[¶](#object.__ipow__ "Permalink to this definition")
`object.``__ilshift__`(*self*, *other*)[¶](#object.__ilshift__ "Permalink to this definition")
`object.``__irshift__`(*self*, *... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
5a320442-8160-52d3-9646-a2e1bb922f1d | docs | python | python_datamodel | 310 | 126 | augmented assignment falls back to the normal methods. For instance, if *x*
is an instance of a class with an [`__iadd__()`](#object.__iadd__ "object.__iadd__") method, `x += y` is
equivalent to `x = x.__iadd__(y)` . Otherwise, `x.__add__(y)` and
`y.__radd__(x)` are considered, as with the evaluation of... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
062f97d1-aa6b-5353-8278-9ae15256951e | docs | python | python_datamodel | 310 | 127 | : Called to implement the unary arithmetic operations (`-`, `+`, [`abs()`](../library/functions.html#abs "abs")
and `~`).
`object.``__complex__`(*self*)[¶](#object.__complex__ "Permalink to this definition")
`object.``__int__`(*self*)[¶](#object.__int__ "Permalink to this definition")
`object.``__float__`(*sel... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
d155e78c-2de6-556f-886b-3e37acd98775 | docs | python | python_datamodel | 310 | 128 | slicing, or in the built-in [`bin()`](../library/functions.html#bin "bin"), [`hex()`](../library/functions.html#hex "hex") and [`oct()`](../library/functions.html#oct "oct")
functions). Presence of this method indicates that the numeric object is
an integer type. Must return an integer.
If [`__int__()`... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
bd55a801-dec2-572e-9989-14635c0ad5bd | docs | python | python_datamodel | 310 | 129 | `object.``__floor__`(*self*)[¶](#object.__floor__ "Permalink to this definition")
`object.``__ceil__`(*self*)[¶](#object.__ceil__ "Permalink to this definition")
: Called to implement the built-in function [`round()`](../library/functions.html#round "round") and [`math`](../library/math.html#module-math "math: Mathe... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
164b6605-cdca-544c-a674-1f84d9df043b | docs | python | python_datamodel | 310 | 130 | [`__int__()`](#object.__int__ "object.__int__") nor [`__index__()`](#object.__index__ "object.__index__") is defined.
### 3.3.9. With Statement Context Managers[¶](#with-statement-context-managers "Permalink to this headline")
A *context manager* is an object that defines the runtime context to be
established whe... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
12bfb1cc-50cb-592f-93d0-b09a43a47c72 | docs | python | python_datamodel | 310 | 131 | `object.``__enter__`(*self*)[¶](#object.__enter__ "Permalink to this definition")
: Enter the runtime context related to this object. The [`with`](compound_stmts.html#with) statement
will bind this method’s return value to the target(s) specified in the
`as` clause of the statement, if any.
`object.``__exit_... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
a9d437f4-dc67-51a4-b8c2-2fe9b592ece4 | docs | python | python_datamodel | 310 | 132 | Note that [`__exit__()`](#object.__exit__ "object.__exit__") methods should not reraise the passed-in exception;
this is the caller’s responsibility.
See also
[**PEP 343**](https://www.python.org/dev/peps/pep-0343) - The “with” statement
: The specification, background, and examples for the Python [`with`](... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
1c9f42c8-7191-5f08-9f41-638d75275d8b | docs | python | python_datamodel | 310 | 133 | used in a class pattern with positional arguments, each positional argument will
be converted into a keyword argument, using the corresponding value in
*\_\_match\_args\_\_* as the keyword. The absence of this attribute is equivalent to
setting it to `()`.
For example, if `MyClass.__match_args__` is `(... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
4f470bf1-cd8a-5e9a-9ad6-4866d38cdcb2 | docs | python | python_datamodel | 310 | 134 | ### 3.3.11. Special method lookup[¶](#special-method-lookup "Permalink to this headline")
For custom classes, implicit invocations of special methods are only guaranteed
to work correctly if defined on an object’s type, not in the object’s instance
dictionary. That behaviour is the reason why the following code raises... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
523ca40a-5745-5fe6-a6aa-e2c6873c716b | docs | python | python_datamodel | 310 | 135 | Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: descriptor '__hash__' of 'int' object needs an argument
```
Incorrectly attempting to invoke an unbound method of a class in this way is
sometimes referred to as ‘metaclass confusion’, and is avoided by bypassing
the instance when look... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
f6952202-ae28-5cb4-beb7-958d5e01a5b0 | docs | python | python_datamodel | 310 | 136 | ... print("Class getattribute invoked")
... return object.__getattribute__(*args)
...
>>> c = C()
>>> c.__len__() # Explicit lookup via instance
Class getattribute invoked
10
>>> type(c).__len__(c) # Explicit lookup via type
Metaclass getattribute invoked
10
>>> len(c) ... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
36441bc1-53e1-5e6e-97ee-9a16b784f68c | docs | python | python_datamodel | 310 | 137 | [Coroutine objects](../glossary.html#term-coroutine) returned from [`async def`](compound_stmts.html#async-def) functions
are awaitable.
Note
The [generator iterator](../glossary.html#term-generator-iterator) objects returned from generators
decorated with [`types.coroutine()`](../library/types.html#types.coroutine "... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
fda41637-8a7d-53ff-8c91-65191cdd213c | docs | python | python_datamodel | 310 | 138 | The language doesn’t place any restriction on the type or value of the
objects yielded by the iterator returned by `__await__`, as this is
specific to the implementation of the asynchronous execution framework
(e.g. [`asyncio`](../library/asyncio.html#module-asyncio "asyncio: Asynchronous I/O.")) that w... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
adf7bd0c-bae5-5b66-8b85-8323a2577529 | docs | python | python_datamodel | 310 | 139 | returns, the iterator raises [`StopIteration`](../library/exceptions.html#StopIteration "StopIteration"), and the exception’s
`value` attribute holds the return value. If the
coroutine raises an exception, it is propagated by the iterator. Coroutines
should not directly raise unhandled [`StopIteration`](../library/exce... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
8e4b9819-1978-58da-818c-ee71d1904dc3 | docs | python | python_datamodel | 310 | 140 | [`__await__()`](#object.__await__ "object.__await__"). If *value* is not `None`, this method delegates
to the [`send()`](expressions.html#generator.send "generator.send") method of the iterator that caused
the coroutine to suspend. The result (return value,
[`StopIteration`](../library/exceptions.html#S... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
5a38235e-e104-5c62-b1ab-52ffc573cbca | docs | python | python_datamodel | 310 | 141 | (return value, [`StopIteration`](../library/exceptions.html#StopIteration "StopIteration"), or other exception) is the same as
when iterating over the [`__await__()`](#object.__await__ "object.__await__") return value, described
above. If the exception is not caught in the coroutine, it propagates
back ... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
8c4c8550-01d3-576b-ad08-b3d40a131308 | docs | python | python_datamodel | 310 | 142 | Coroutine objects are automatically closed using the above process when
they are about to be destroyed.
### 3.4.3. Asynchronous Iterators[¶](#asynchronous-iterators "Permalink to this headline")
An *asynchronous iterator* can call asynchronous code in
its `__anext__` method.
Asynchronous iterators can be use... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
5d26d2ab-4d8b-5ea0-92bf-dc9c9b7c013a | docs | python | python_datamodel | 310 | 143 | val = await self.readline()
if val == b'':
raise StopAsyncIteration
return val
```
New in version 3.5.
Changed in version 3.7: Prior to Python 3.7, [`__aiter__()`](#object.__aiter__ "object.__aiter__") could return an *awaitable*
that would resolve to an
[asynchronous iterator](../... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
cfeed89b-0eaf-55ca-8665-51ec2a7dcdef | docs | python | python_datamodel | 310 | 144 | `object.``__aenter__`(*self*)[¶](#object.__aenter__ "Permalink to this definition")
: Semantically similar to [`__enter__()`](#object.__enter__ "object.__enter__"), the only
difference being that it must return an *awaitable*.
`object.``__aexit__`(*self*, *exc\_type*, *exc\_value*, *traceback*)[¶](#object.__aexi... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
572bc8d0-7008-5ca5-ac4c-88cdb443d5fe | docs | python | python_datamodel | 310 | 145 | [2](#id2)
: The [`__hash__()`](#object.__hash__ "object.__hash__"), [`__iter__()`](#object.__iter__ "object.__iter__"),
[`__reversed__()`](#object.__reversed__ "object.__reversed__"), and [`__contains__()`](#object.__contains__ "object.__contains__") methods have
special handling for this; others
will sti... | large_dataset/raw/docs/python/datamodel/datamodel_310.md |
d96e9ef3-be57-59f5-934a-0ec15edcafe9 | docs | python | python_datamodel | 310 | 146 | supported, which is why the reflected method is not called.
| large_dataset/raw/docs/python/datamodel/datamodel_310.md |
7dc36576-10d0-559e-b39a-6ebd18a6d50f | docs | python | python_datamodel | 311 | 0 | # 3.Data model¶
Source: https://docs.python.org/3.11/reference/datamodel.html
Version: 3.11
## 3.1. Objects, values and types[¶](#objects-values-and-types "Link to this heading")
*Objects* are Python’s abstraction for data. All data in a Python program
is represented by objects or by relations between objects. (In a... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
6c45f005-ea00-5d35-a949-d058b33e2ee6 | docs | python | python_datamodel | 311 | 1 | it have a length?”) and also defines the possible values for objects of that
type. The [`type()`](../library/functions.html#type "type") function returns an object’s type (which is an object
itself). Like its identity, an object’s *type* is also unchangeable.
[[1]](#id17)
The *value* of some objects can change. Object... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
dbe1909a-69e0-50d9-8f0b-f668883e288f | docs | python | python_datamodel | 311 | 2 | Objects are never explicitly destroyed; however, when they become unreachable
they may be garbage-collected. An implementation is allowed to postpone garbage
collection or omit it altogether — it is a matter of implementation quality
how garbage collection is implemented, as long as no objects are collected that
are st... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
837f141a-79f6-56ee-bc6a-b44caa3e60dc | docs | python | python_datamodel | 311 | 3 | Note that the use of the implementation’s tracing or debugging facilities may
keep objects alive that would normally be collectable. Also note that catching
an exception with a [`try`](compound_stmts.html#try)…[`except`](compound_stmts.html#except) statement may keep
objects alive.
Some objects contain references to “... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
d3175fbf-ff05-5065-8695-15480fa17fd1 | docs | python | python_datamodel | 311 | 4 | part of a container’s value. In most cases, when we talk about the value of a
container, we imply the values, not the identities of the contained objects;
however, when we talk about the mutability of a container, only the identities
of the immediately contained objects are implied. So, if an immutable container
(like ... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
adf58c2e-7178-5ac8-ad37-d8a73d5249b4 | docs | python | python_datamodel | 311 | 5 | created empty lists. (Note that `c = d = []` assigns the same object to both
`c` and `d`.)
## 3.2. The standard type hierarchy[¶](#the-standard-type-hierarchy "Link to this heading")
Below is a list of the types that are built into Python. Extension modules
(written in C, Java, or other languages, depending on the im... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
5e405946-f468-5488-ad92-00f619a31eb3 | docs | python | python_datamodel | 311 | 6 | ### 3.2.1. None[¶](#none "Link to this heading")
This type has a single value. There is a single object with this value. This
object is accessed through the built-in name `None`. It is used to signify the
absence of a value in many situations, e.g., it is returned from functions that
don’t explicitly return anything. ... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
ee879679-e3ea-5ecd-ac9d-e957ac94983b | docs | python | python_datamodel | 311 | 7 | for more details.
Changed in version 3.9: Evaluating [`NotImplemented`](../library/constants.html#NotImplemented "NotImplemented") in a boolean context is deprecated. While
it currently evaluates as true, it will emit a [`DeprecationWarning`](../library/exceptions.html#DeprecationWarning "DeprecationWarning").
It will... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
528c376e-5e71-5287-81d5-20ad759a6c88 | docs | python | python_datamodel | 311 | 8 | related to mathematical numbers, but subject to the limitations of numerical
representation in computers.
The string representations of the numeric classes, computed by
[`__repr__()`](#object.__repr__ "object.__repr__") and [`__str__()`](#object.__str__ "object.__str__"), have the following
properties:
* They are val... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
86e1ea3a-a06f-5100-8ba0-cd0d9d02f2fc | docs | python | python_datamodel | 311 | 9 | #### 3.2.4.1. [`numbers.Integral`](../library/numbers.html#numbers.Integral "numbers.Integral")[¶](#numbers-integral "Link to this heading")
These represent elements from the mathematical set of integers (positive and
negative).
Note
The rules for integer representation are intended to give the most meaningful
inter... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
988d25f1-61dc-5c9b-b9eb-d78442755125 | docs | python | python_datamodel | 311 | 10 | the values `False` and `True` are the only Boolean objects. The Boolean type is a
subtype of the integer type, and Boolean values behave like the values 0 and 1,
respectively, in almost all contexts, the exception being that when converted to
a string, the strings `"False"` or `"True"` are returned, res... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
fbe29ca5-889f-5f7b-9de5-303294e93713 | docs | python | python_datamodel | 311 | 11 | language with two kinds of floating point numbers.
#### 3.2.4.3. [`numbers.Complex`](../library/numbers.html#numbers.Complex "numbers.Complex") ([`complex`](../library/functions.html#complex "complex"))[¶](#numbers-complex-complex "Link to this heading")
These represent complex numbers as a pair of machine-level doub... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
28f1fe0d-a5ac-58b6-bdfa-4b76d40b13ae | docs | python | python_datamodel | 311 | 12 | sequence length. For example, `a[-2]` equals `a[n-2]`, the second to last
item of sequence a with length `n`.
Sequences also support slicing: `a[i:j]` selects all items with index *k* such
that *i* `<=` *k* `<` *j*. When used as an expression, a slice is a
sequence of the same type. The comment above about negative in... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
4554b46f-daa2-526f-aba0-efd533de8fdf | docs | python | python_datamodel | 311 | 13 | Strings
: A string is a sequence of values that represent Unicode code points.
All the code points in the range `U+0000 - U+10FFFF` can be
represented in a string. Python doesn’t have a char type;
instead, every code point in the string is represented as a string
object with length `1`. The built-in f... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
c1275c01-1adc-5569-8cb8-e8a0b97fb4d3 | docs | python | python_datamodel | 311 | 14 | : The items of a tuple are arbitrary Python objects. Tuples of two or
more items are formed by comma-separated lists of expressions. A tuple
of one item (a ‘singleton’) can be formed by affixing a comma to an
expression (an expression by itself does not create a tuple, since
parentheses must be usable... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
2ba707ba-897c-5f02-8d5c-5670234c300e | docs | python | python_datamodel | 311 | 15 | #### 3.2.5.2. Mutable sequences[¶](#mutable-sequences "Link to this heading")
Mutable sequences can be changed after they are created. The subscription and
slicing notations can be used as the target of assignment and [`del`](simple_stmts.html#del)
(delete) statements.
Note
The [`collections`](../library/collections... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
9cf97ae4-c695-5b02-92f2-66327aff3aa4 | docs | python | python_datamodel | 311 | 16 | [`bytearray()`](../library/stdtypes.html#bytearray "bytearray") constructor. Aside from being mutable
(and hence unhashable), byte arrays otherwise provide the same interface
and functionality as immutable [`bytes`](../library/stdtypes.html#bytes "bytes") objects.
### 3.2.6. Set types[¶](#set-types "Link t... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
a9f3250b-4850-5618-ab53-870ae1dfeaf4 | docs | python | python_datamodel | 311 | 17 | compare equal (e.g., `1` and `1.0`), only one of them can be contained in a
set.
There are currently two intrinsic set types:
Sets
: These represent a mutable set. They are created by the built-in [`set()`](../library/stdtypes.html#set "set")
constructor and can be modified afterwards by several methods, such a... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
affd9066-fbf0-5c02-9b00-b661d223051f | docs | python | python_datamodel | 311 | 18 | [`del`](simple_stmts.html#del) statements. The built-in function [`len()`](../library/functions.html#len "len") returns the number
of items in a mapping.
There is currently a single intrinsic mapping type:
#### 3.2.7.1. Dictionaries[¶](#dictionaries "Link to this heading")
These represent finite sets of objects inde... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
7e8cb9cc-4876-5564-a450-ecb62bd751fb | docs | python | python_datamodel | 311 | 19 | Replacing an existing key does not change the order, however removing a key
and re-inserting it will add it to the end instead of keeping its old place.
Dictionaries are mutable; they can be created by the `{...}` notation (see
section [Dictionary displays](expressions.html#dict)).
The extension modules [`dbm.ndbm`](... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
aeb71b96-bd16-56ac-bd17-5a2109ac3333 | docs | python | python_datamodel | 311 | 20 | ### 3.2.8. Callable types[¶](#callable-types "Link to this heading")
These are the types to which the function call operation (see section
[Calls](expressions.html#calls)) can be applied:
#### 3.2.8.1. User-defined functions[¶](#user-defined-functions "Link to this heading")
A user-defined function object is created... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
97d41106-bd91-5730-b207-2f52e8b4b039 | docs | python | python_datamodel | 311 | 21 | | function.\_\_closure\_\_[¶](#function.__closure__ "Link to this definition") | `None` or a [`tuple`](../library/stdtypes.html#tuple "tuple") of cells that contain bindings for the function’s free variables. A cell object has the attribute `cell_contents`. This can be used to get the value of the cell, as well as set... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
c9ce0396-3292-5b07-beb7-6c013be2a459 | docs | python | python_datamodel | 311 | 22 | | function.\_\_qualname\_\_[¶](#function.__qualname__ "Link to this definition") | The function’s [qualified name](../glossary.html#term-qualified-name). See also: [`__qualname__ attributes`](../library/stdtypes.html#definition.__qualname__ "definition.__qualname__"). New in version 3.3. |
| function.\_\_module\_\_[¶]... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
e66baa50-9975-5028-b257-e78c1b1643c7 | docs | python | python_datamodel | 311 | 23 | | function.\_\_dict\_\_[¶](#function.__dict__ "Link to this definition") | The namespace supporting arbitrary function attributes. See also: [`__dict__ attributes`](../library/stdtypes.html#object.__dict__ "object.__dict__"). |
| function.\_\_annotations\_\_[¶](#function.__annotations__ "Link to this definition") | A [... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
4a71e6fc-6d05-582d-b060-ca82076d7e45 | docs | python | python_datamodel | 311 | 24 | dot-notation is used to get and set such attributes.
**CPython implementation detail:** CPython’s current implementation only supports function attributes
on user-defined functions. Function attributes on
[built-in functions](#builtin-functions) may be supported in the
future.
Additional information about a function’... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
abe36e26-f447-5d8b-97f2-13a518d6a683 | docs | python | python_datamodel | 311 | 25 | | method.\_\_doc\_\_[¶](#method.__doc__ "Link to this definition") | The method’s documentation (same as [`method.__func__.__doc__`](#function.__doc__ "function.__doc__")). A [`string`](../library/stdtypes.html#str "str") if the original function had a docstring, else `None`. |
| method.\_\_name\_\_[¶](#method.__name__... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
886fc32b-9c3c-5913-92e7-3c04980afb73 | docs | python | python_datamodel | 311 | 26 | [`classmethod`](../library/functions.html#classmethod "classmethod") object.
When an instance method object is created by retrieving a user-defined
[function object](#user-defined-funcs) from a class via one of its
instances, its [`__self__`](#method.__self__ "method.__self__") attribute is the instance, and the
metho... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
989e8514-5e54-5ae9-b408-6ea1ebf3dae0 | docs | python | python_datamodel | 311 | 27 | ([`__self__`](#method.__self__ "method.__self__")) in front of the argument list. For instance, when
`C` is a class which contains a definition for a function
`f()`, and `x` is an instance of `C`, calling `x.f(1)` is
equivalent to calling `C.f(x, 1)`.
When an instance method object is derived from a [`classmethod`](..... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
ea6b55b5-2f45-5ffb-bff7-bfc0ff24e804 | docs | python | python_datamodel | 311 | 28 | objects (and all non-callable objects) are retrieved without
transformation. It is also important to note that user-defined functions
which are attributes of a class instance are not converted to bound
methods; this *only* happens when the function is an attribute of the
class.
#### 3.2.8.3. Generator functions[¶](#ge... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
4f1ea693-b10e-5a37-a911-0ce254650897 | docs | python | python_datamodel | 311 | 29 | [`StopIteration`](../library/exceptions.html#StopIteration "StopIteration") exception is raised and the iterator will have
reached the end of the set of values to be returned.
#### 3.2.8.4. Coroutine functions[¶](#coroutine-functions "Link to this heading")
A function or method which is defined using [`async def`](co... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
62d84655-bced-5ba3-9b52-361f9d23873a | docs | python | python_datamodel | 311 | 30 | *asynchronous generator function*. Such a function, when called,
returns an [asynchronous iterator](../glossary.html#term-asynchronous-iterator) object which can be used in an
[`async for`](compound_stmts.html#async-for) statement to execute the body of the function.
Calling the asynchronous iterator’s
[`aiterator.__a... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
473f6cc5-0e07-5a2c-bd88-a9fd919f4925 | docs | python | python_datamodel | 311 | 31 | #### 3.2.8.6. Built-in functions[¶](#built-in-functions "Link to this heading")
A built-in function object is a wrapper around a C function. Examples of
built-in functions are [`len()`](../library/functions.html#len "len") and [`math.sin()`](../library/math.html#math.sin "math.sin") ([`math`](../library/math.html#modu... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
6ee79242-5378-5d4a-a574-48adf993d625 | docs | python | python_datamodel | 311 | 32 | #### 3.2.8.7. Built-in methods[¶](#built-in-methods "Link to this heading")
This is really a different disguise of a built-in function, this time containing
an object passed to the C function as an implicit extra argument. An example of
a built-in method is `alist.append()`, assuming *alist* is a list object. In
this ... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
f6462d29-832c-516f-80ed-f61e3ce3a7ae | docs | python | python_datamodel | 311 | 33 | #### 3.2.8.9. Class Instances[¶](#class-instances "Link to this heading")
Instances of arbitrary classes can be made callable by defining a
[`__call__()`](#object.__call__ "object.__call__") method in their class.
### 3.2.9. Modules[¶](#modules "Link to this heading")
Modules are a basic organizational unit of Pytho... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
6c8fea2f-d757-5887-9301-d4dd8e1d6839 | docs | python | python_datamodel | 311 | 34 | translated to lookups in this dictionary, e.g., `m.x` is equivalent to
`m.__dict__["x"]`. A module object does not contain the code object used
to initialize the module (since it isn’t needed once the initialization is
done).
Attribute assignment updates the module’s namespace dictionary, e.g.,
`m.x = 1` is equivalent... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
e50c9f60-a27d-5074-ac1c-782deccd4250 | docs | python | python_datamodel | 311 | 35 | > : A dictionary containing
> [variable annotations](../glossary.html#term-variable-annotation) collected during
> module body execution. For best practices on working
> with `__annotations__`, please see [Annotations Best Practices](../howto/annotations.html#annotations-howto).
Special read-only attribu... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
48c21ba2-d30e-57df-b9ab-44a0236bb9fd | docs | python | python_datamodel | 311 | 36 | Class attribute references are translated to lookups in this dictionary, e.g.,
`C.x` is translated to `C.__dict__["x"]` (although there are a number of
hooks which allow for other means of locating attributes). When the attribute
name is not found there, the attribute search continues in the base classes.
This search o... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
812804e1-9810-5c8b-90f1-5eacc4fe85b6 | docs | python | python_datamodel | 311 | 37 | it is transformed into the object wrapped by the static method
object. See section [Implementing Descriptors](#descriptors) for another way in which attributes
retrieved from a class may differ from those actually contained in its
[`__dict__`](../library/stdtypes.html#object.__dict__ "object.__dict__").
Class attribut... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
37282ad7-0620-55cc-bc1d-2edb2a44b5b2 | docs | python | python_datamodel | 311 | 38 | > : The class’s documentation string, or `None` if undefined.
>
> `__annotations__`
> : A dictionary containing
> [variable annotations](../glossary.html#term-variable-annotation)
> collected during class body execution. For best practices on
> working with `__annotations__`, please see
> [Annotatio... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
c5ad8be9-7ac6-53ee-b222-68c2c23e66e3 | docs | python | python_datamodel | 311 | 39 | class method objects are also transformed; see above under “Classes”. See
section [Implementing Descriptors](#descriptors) for another way in which attributes of a class
retrieved via its instances may differ from the objects actually stored in
the class’s [`__dict__`](../library/stdtypes.html#object.__dict__ "object._... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
30b33ac3-7d93-57a9-82ca-35024bd7d766 | docs | python | python_datamodel | 311 | 40 | Special attributes: [`__dict__`](../library/stdtypes.html#object.__dict__ "object.__dict__") is the attribute dictionary;
[`__class__`](../library/stdtypes.html#instance.__class__ "instance.__class__") is the instance’s class.
### 3.2.12. I/O objects (also known as file objects)[¶](#i-o-objects-also-known-as-file-obje... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
2de79811-cc91-511c-b650-36fe5529e4af | docs | python | python_datamodel | 311 | 41 | input, output and error streams; they are all open in text mode and
therefore follow the interface defined by the [`io.TextIOBase`](../library/io.html#io.TextIOBase "io.TextIOBase")
abstract class.
### 3.2.13. Internal types[¶](#internal-types "Link to this heading")
A few types used internally by the interpreter are... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
ef89d041-7a12-59b5-b81f-088c337659d7 | docs | python | python_datamodel | 311 | 42 | objects, code objects are immutable and contain no references (directly or
indirectly) to mutable objects.
##### 3.2.13.1.1. Special read-only attributes[¶](#index-58 "Link to this heading")
| | |
| --- | --- |
| codeobject.co\_name[¶](#codeobject.co_name "Link to this definition") | The function name |
| codeobjec... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
70479195-d1b6-5e71-b5f8-ae5fcf683253 | docs | python | python_datamodel | 311 | 43 | | codeobject.co\_kwonlyargcount[¶](#codeobject.co_kwonlyargcount "Link to this definition") | The number of keyword-only [parameters](../glossary.html#term-parameter) (including arguments with default values) that the function has |
| codeobject.co\_nlocals[¶](#codeobject.co_nlocals "Link to this definition") | The num... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
7edb2445-ed56-568d-83d3-27b912058fcb | docs | python | python_datamodel | 311 | 44 | | codeobject.co\_freevars[¶](#codeobject.co_freevars "Link to this definition") | A [`tuple`](../library/stdtypes.html#tuple "tuple") containing the names of free variables in the function |
| codeobject.co\_code[¶](#codeobject.co_code "Link to this definition") | A string representing the sequence of [bytecode](../glo... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
a75d9586-9ce7-5862-b3a9-506ad8ea1ce1 | docs | python | python_datamodel | 311 | 45 | | codeobject.co\_firstlineno[¶](#codeobject.co_firstlineno "Link to this definition") | The line number of the first line of the function |
| codeobject.co\_lnotab[¶](#codeobject.co_lnotab "Link to this definition") | A string encoding the mapping from [bytecode](../glossary.html#term-bytecode) offsets to line numbers.... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
4466e18d-da39-543b-a602-d75bbef2616f | docs | python | python_datamodel | 311 | 46 | if the function is a generator. See [Code Objects Bit Flags](../library/inspect.html#inspect-module-co-flags) for details
on the semantics of each flags that might be present.
Future feature declarations (`from __future__ import division`) also use bits
in [`co_flags`](#codeobject.co_flags "codeobject.co_flags") to in... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
3e0f96d6-1b54-53ec-9b02-4d47691fab81 | docs | python | python_datamodel | 311 | 47 | ##### 3.2.13.1.2. Methods on code objects[¶](#methods-on-code-objects "Link to this heading")
codeobject.co\_positions()[¶](#codeobject.co_positions "Link to this definition")
: Returns an iterable over the source code positions of each [bytecode](../glossary.html#term-bytecode)
instruction in the code object.
... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
1e405d39-312a-5f21-9410-a1ab7c9f67ce | docs | python | python_datamodel | 311 | 48 | * Position tuples corresponding to artificial instructions.
* Line and column numbers that can’t be represented due to
implementation specific limitations.
When this occurs, some or all of the tuple elements can be
[`None`](../library/constants.html#None "None").
New in version 3.11.
No... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
1125bf55-7d7d-507d-bb0a-8339d017ad52 | docs | python | python_datamodel | 311 | 49 | [bytecode](../glossary.html#term-bytecode)s. Each item yielded is a `(start, end, lineno)`
[`tuple`](../library/stdtypes.html#tuple "tuple"):
* `start` (an [`int`](../library/functions.html#int "int")) represents the offset (inclusive) of the start
of the [bytecode](../glossary.html#term-bytecode) ra... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
c49ebde5-3b85-5089-82b0-ade023a06654 | docs | python | python_datamodel | 311 | 50 | is, for any pair of [`tuple`](../library/stdtypes.html#tuple "tuple")s, the `start` of the second will be
equal to the `end` of the first.
* No range will be backwards: `end >= start` for all triples.
* The last [`tuple`](../library/stdtypes.html#tuple "tuple") yielded will have `end` equal to the s... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
428bad6a-8322-51f9-a9c5-572f3c4c15f4 | docs | python | python_datamodel | 311 | 51 | #### 3.2.13.2. Frame objects[¶](#frame-objects "Link to this heading")
Frame objects represent execution frames. They may occur in
[traceback objects](#traceback-objects),
and are also passed to registered trace functions.
##### 3.2.13.2.1. Special read-only attributes[¶](#index-64 "Link to this heading")
| | |
| ... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
24320007-d247-5a8d-b85f-892e21a258d0 | docs | python | python_datamodel | 311 | 52 | | frame.f\_globals[¶](#frame.f_globals "Link to this definition") | The dictionary used by the frame to look up [global variables](executionmodel.html#naming) |
| frame.f\_builtins[¶](#frame.f_builtins "Link to this definition") | The dictionary used by the frame to look up [built-in (intrinsic) names](executionmodel.h... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
a7f291f2-b2a5-5a3c-b18d-1bcf333e2db4 | docs | python | python_datamodel | 311 | 53 | | frame.f\_trace\_lines[¶](#frame.f_trace_lines "Link to this definition") | Set this attribute to [`False`](../library/constants.html#False "False") to disable triggering a tracing event for each source line. |
| frame.f\_trace\_opcodes[¶](#frame.f_trace_opcodes "Link to this definition") | Set this attribute to [`Tru... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
1a083eaf-c9f4-5507-947f-72e579bd636d | docs | python | python_datamodel | 311 | 54 | ##### 3.2.13.2.3. Frame object methods[¶](#frame-object-methods "Link to this heading")
Frame objects support one method:
frame.clear()[¶](#frame.clear "Link to this definition")
: This method clears all references to [local variables](executionmodel.html#naming) held by the
frame. Also, if the frame belonged t... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
85ee76c3-04d4-56d8-a83a-49a7d66a3afc | docs | python | python_datamodel | 311 | 55 | is implicitly created when an exception occurs, and may also be explicitly
created by calling [`types.TracebackType`](../library/types.html#types.TracebackType "types.TracebackType").
Changed in version 3.7: Traceback objects can now be explicitly instantiated from Python code.
For implicitly created tracebacks, when... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
438418ee-3dec-595e-8e37-7059f245cd14 | docs | python | python_datamodel | 311 | 56 | stream; if the interpreter is interactive, it is also made available to the user
as [`sys.last_traceback`](../library/sys.html#sys.last_traceback "sys.last_traceback").
For explicitly created tracebacks, it is up to the creator of the traceback
to determine how the [`tb_next`](#traceback.tb_next "traceback.tb_next") a... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
34de731f-afbb-5baa-abdb-a349c560425f | docs | python | python_datamodel | 311 | 57 | The line number and last instruction in the traceback may differ from the
line number of its [frame object](#frame-objects) if the exception
occurred in a
[`try`](compound_stmts.html#try) statement with no matching except clause or with a
[`finally`](compound_stmts.html#finally) clause.
traceback.tb\_next[¶](#tracebac... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
cfa55ca3-b9d4-5d2c-a161-070b34eb1779 | docs | python | python_datamodel | 311 | 58 | [`stop`](../library/functions.html#slice.stop "slice.stop") is the upper bound; [`step`](../library/functions.html#slice.step "slice.step") is the step
value; each is `None` if omitted. These attributes can have any type.
Slice objects support one method:
slice.indices(*self*, *length*)[¶](#slice.indices "Link to thi... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
f33e45e3-646a-5410-8b96-107b0371c6f5 | docs | python | python_datamodel | 311 | 59 | around any other object, usually a user-defined method object. When a static
method object is retrieved from a class or a class instance, the object actually
returned is the wrapped object, which is not subject to any further
transformation. Static method objects are also callable. Static method
objects are created by ... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
3a48d856-c722-5928-8674-5dda0895b856 | docs | python | python_datamodel | 311 | 60 | ## 3.3. Special method names[¶](#special-method-names "Link to this heading")
A class can implement certain operations that are invoked by special syntax
(such as arithmetic operations or subscripting and slicing) by defining methods
with special names. This is Python’s approach to *operator overloading*,
allowing cla... | large_dataset/raw/docs/python/datamodel/datamodel_311.md |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.