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
e1f603c4-b9b4-5d90-aeae-2bbf39627149
docs
python
python_stdtypes
311
138
| `'G'` | Floating point format. Uses uppercase exponential format if exponent is less than -4 or not less than precision, decimal format otherwise. | (4) | | `'c'` | Single byte (accepts integer or single byte objects). | | | `'b'` | Bytes (any object that follows the [buffer protocol](../c-api/buffer.html#bufferobje...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
8c0b20b8-b851-5303-9ac6-2e42ba3dcd9d
docs
python
python_stdtypes
311
139
the `'x'` or `'X'` format was used) to be inserted before the first digit. 3. The alternate form causes the result to always contain a decimal point, even if no digits follow it. The precision determines the number of digits after the decimal point and defaults to 6. 4. The alternate form causes the result...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
3219e175-5116-5dfd-b787-6f58de63010a
docs
python
python_stdtypes
311
140
[**PEP 461**](https://peps.python.org/pep-0461/) - Adding % formatting to bytes and bytearray New in version 3.5. ### Memory Views[¶](#memory-views "Link to this heading") [`memoryview`](#memoryview "memoryview") objects allow Python code to access the internal data of an object that supports the [buffer protocol](....
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
c24cd9c1-2782-5673-a546-dd2c7b94eade
docs
python
python_stdtypes
311
141
byte, but other types such as [`array.array`](array.html#array.array "array.array") may have bigger elements. `len(view)` is equal to the length of [`tolist`](#memoryview.tolist "memoryview.tolist"). If `view.ndim = 0`, the length is 1. If `view.ndim = 1`, the length is equal to the number of elements ...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
d0933d6a-488b-5165-93a4-edcdba48f147
docs
python
python_stdtypes
311
142
from the [`struct`](struct.html#module-struct "struct: Interpret bytes as packed binary data.") module, indexing with an integer or a tuple of integers is also supported and returns a single *element* with the correct type. One-dimensional memoryviews can be indexed with an integer or a one-integer tupl...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
2d710f58-d7da-5971-b5fa-a2a6985e6d9b
docs
python
python_stdtypes
311
143
>>> v = memoryview(data) >>> v.readonly False >>> v[0] = ord(b'z') >>> data bytearray(b'zbcefg') >>> v[1:4] = b'123' >>> data bytearray(b'z123fg') >>> v[2:3] = b'spam' Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: memoryview assi...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
54b5e258-7df4-55ea-bae6-0016c603b967
docs
python
python_stdtypes
311
144
One-dimensional memoryviews with formats ‘B’, ‘b’ or ‘c’ are now [hashable](../glossary.html#term-hashable). Changed in version 3.4: memoryview is now registered automatically with [`collections.abc.Sequence`](collections.abc.html#collections.abc.Sequence "collections.abc.Sequence") Changed in version...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
4fa4c053-8222-5dd6-bb9e-483f66a8ebb5
docs
python
python_stdtypes
311
145
[`tolist()`](#memoryview.tolist "memoryview.tolist"), `v` and `w` are equal if `v.tolist() == w.tolist()`: ```None >>> import array >>> a = array.array('I', [1, 2, 3, 4, 5]) >>> b = array.array('d', [1.0, 2.0, 3.0, 4.0, 5.0]) >>> c = array.array('b', [5, 3, 1]) >...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
f6500ed1-a59b-5b1d-8355-ef8697b2e685
docs
python
python_stdtypes
311
146
... _fields_ = [("x", c_long), ("y", c_long)] ... >>> point = BEPoint(100, 200) >>> a = memoryview(point) >>> b = memoryview(point) >>> a == point False >>> a == b False ``` Note that, as with floating point numbers, `v is w` d...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
5b500254-09ab-5dbe-8298-56b74972b99b
docs
python
python_stdtypes
311
147
representation with all elements converted to bytes. [`tobytes()`](#memoryview.tobytes "memoryview.tobytes") supports all format strings, including those that are not in [`struct`](struct.html#module-struct "struct: Interpret bytes as packed binary data.") module syntax. New in version ...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
34a0a052-1d0a-5595-8ac3-d2bc65997715
docs
python
python_stdtypes
311
148
New in version 3.5. Changed in version 3.8: Similar to [`bytes.hex()`](#bytes.hex "bytes.hex"), [`memoryview.hex()`](#memoryview.hex "memoryview.hex") now supports optional *sep* and *bytes\_per\_sep* parameters to insert separators between bytes in the hex output. tolist()[¶](#mem...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
eb378a9a-e834-513c-b68d-da2537809fac
docs
python
python_stdtypes
311
149
toreadonly()[¶](#memoryview.toreadonly "Link to this definition") : Return a readonly version of the memoryview object. The original memoryview object is unchanged. ```None >>> m = memoryview(bytearray(b'abc')) >>> mm = m.toreadonly() >>> mm.tolist() [97, 98, 9...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
15c793b7-7592-5c25-9026-0590ac364ad9
docs
python
python_stdtypes
311
150
dangling resources) as soon as possible. After this method has been called, any further operation on the view raises a [`ValueError`](exceptions.html#ValueError "ValueError") (except [`release()`](#memoryview.release "memoryview.release") itself which can be called multiple times): ...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
4bda925c-95f3-53cc-9312-8cd651b771c4
docs
python
python_stdtypes
311
151
cast(*format*[, *shape*])[¶](#memoryview.cast "Link to this definition") : Cast a memoryview to a new format or shape. *shape* defaults to `[byte_length//new_itemsize]`, which means that the result view will be one-dimensional. The return value is a new memoryview, but the buffer itsel...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
2a99ae75-50cb-52a8-b994-b40f60129c9a
docs
python
python_stdtypes
311
152
>>> x.format 'l' >>> x.itemsize 8 >>> len(x) 3 >>> x.nbytes 24 >>> y = x.cast('B') >>> y.format 'B' >>> y.itemsize 1 >>> len(y) 24 >>> y.nbytes 24 ``` Cast 1D/unsigned...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
9a6b2c9a-5ae8-587a-9a32-9b527eefbd39
docs
python
python_stdtypes
311
153
>>> y.itemsize 4 >>> len(y) 2 >>> y.nbytes 48 >>> z = y.cast('b') >>> z.format 'b' >>> z.itemsize 1 >>> len(z) 48 >>> z.nbytes 48 ``` Cast 1D/unsigned long to 2D/unsigned long: ...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
cd3f0467-93f2-5f80-ac86-9e8f027ce9fb
docs
python
python_stdtypes
311
154
New in version 3.3. nbytes[¶](#memoryview.nbytes "Link to this definition") : `nbytes == product(shape) * itemsize == len(m.tobytes())`. This is the amount of space in bytes that the array would use in a contiguous representation. It is not necessarily equal to `len(m)`: ```N...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
8a44e179-59d5-5a17-bd00-0d3ac613f592
docs
python
python_stdtypes
311
155
New in version 3.3. readonly[¶](#memoryview.readonly "Link to this definition") : A bool indicating whether the memory is read only. format[¶](#memoryview.format "Link to this definition") : A string containing the format (in [`struct`](struct.html#module-struct "struct: Interpret bytes as...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
366b2d61-9e5c-5cc1-9026-54803b46422c
docs
python
python_stdtypes
311
156
>>> m.itemsize 2 >>> m[0] 32000 >>> struct.calcsize('H') == m.itemsize True ``` ndim[¶](#memoryview.ndim "Link to this definition") : An integer indicating how many dimensions of a multi-dimensional array the memory represents. shape[¶](#me...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
a17f0c00-8809-55e2-afe4-50f38aeb0b5f
docs
python
python_stdtypes
311
157
: Used internally for PIL-style arrays. The value is informational only. c\_contiguous[¶](#memoryview.c_contiguous "Link to this definition") : A bool indicating whether the memory is C-[contiguous](../glossary.html#term-contiguous). New in version 3.3. f\_contiguous[¶](#memoryview.f_cont...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
ac9f06bd-18da-5552-abee-aaba612ea004
docs
python
python_stdtypes
311
158
computing mathematical operations such as intersection, union, difference, and symmetric difference. (For other containers see the built-in [`dict`](#dict "dict"), [`list`](#list "list"), and [`tuple`](#tuple "tuple") classes, and the [`collections`](collections.html#module-collections "collections: Container datatypes...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
fe982118-dc54-52ca-a493-4f7a2528694f
docs
python
python_stdtypes
311
159
another set. The [`frozenset`](#frozenset "frozenset") type is immutable and [hashable](../glossary.html#term-hashable) — its contents cannot be altered after it is created; it can therefore be used as a dictionary key or as an element of another set. Non-empty sets (not frozensets) can be created by placing a comma-s...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
e8f8e134-1790-56e7-9605-024caba8a5c7
docs
python
python_stdtypes
311
160
* Use a comma-separated list of elements within braces: `{'jack', 'sjoerd'}` * Use a set comprehension: `{c for c in 'abracadabra' if c not in 'abc'}` * Use the type constructor: `set()`, `set('foobar')`, `set(['a', 'b', 'foo'])` Instances of [`set`](#set "set") and [`frozenset`](#frozenset "frozenset"...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
c5baa243-e82f-52b9-a314-7ea11c515900
docs
python
python_stdtypes
311
161
`set <= other and set != other`. issuperset(*other*)[¶](#frozenset.issuperset "Link to this definition") set >= other : Test whether every element in *other* is in the set. set > other : Test whether the set is a proper superset of *other*, that is, `set >= other and set != ot...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
d9618e20-d781-5438-afb5-15ae415d8d1e
docs
python
python_stdtypes
311
162
: Return a new set with elements in either the set or *other* but not both. copy()[¶](#frozenset.copy "Link to this definition") : Return a shallow copy of the set. Note, the non-operator versions of [`union()`](#frozenset.union "frozenset.union"), [`intersection()`](#frozenset.intersection "froze...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
25c2e488-f0fc-5899-b848-2a51e20b5c24
docs
python
python_stdtypes
311
163
sets are equal if and only if every element of each set is contained in the other (each is a subset of the other). A set is less than another set if and only if the first set is a proper subset of the second set (is a subset, but is not equal). A set is greater than another set if and only if the first ...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
efd11e46-3b90-56ac-bcff-53e9e9426263
docs
python
python_stdtypes
311
164
the [`list.sort()`](#list.sort "list.sort") method is undefined for lists of sets. Set elements, like dictionary keys, must be [hashable](../glossary.html#term-hashable). Binary operations that mix [`set`](#set "set") instances with [`frozenset`](#frozenset "frozenset") return the type of the first op...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
71fb6ce2-5b09-5fdf-a2ef-a279c8f9a1f1
docs
python
python_stdtypes
311
165
difference\_update(*\*others*)[¶](#frozenset.difference_update "Link to this definition") set -= other | ... : Update the set, removing elements found in others. symmetric\_difference\_update(*other*)[¶](#frozenset.symmetric_difference_update "Link to this definition") set ^= other : Upda...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
5b061659-9fbc-593b-898f-e78be0bfba71
docs
python
python_stdtypes
311
166
[`KeyError`](exceptions.html#KeyError "KeyError") if the set is empty. clear()[¶](#frozenset.clear "Link to this definition") : Remove all elements from the set. Note, the non-operator versions of the [`update()`](#frozenset.update "frozenset.update"), [`intersection_update()`](#frozenset.in...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
7376db48-c02d-5fd5-8ce6-e47f2bc4dcca
docs
python
python_stdtypes
311
167
## Mapping Types — [`dict`](#dict "dict")[¶](#mapping-types-dict "Link to this heading") A [mapping](../glossary.html#term-mapping) object maps [hashable](../glossary.html#term-hashable) values to arbitrary objects. Mappings are mutable objects. There is currently only one standard mapping type, the *dictionary*. (For...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
241d8ebd-0720-5215-b372-21cc0d362ea2
docs
python
python_stdtypes
311
168
*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. Dictionaries can be created by several means: * Use a comma-separated list of `key: value` pairs within ...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
3b1cffe4-c578-5f4e-a7f2-8dc2e3e5f8fc
docs
python
python_stdtypes
311
169
first object of each item becomes a key in the new dictionary, and the second object the corresponding value. If a key occurs more than once, the last value for that key becomes the corresponding value in the new dictionary. If keyword arguments are given, the keyword arguments and their values are...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
7a208bb2-04cc-536c-a3fe-b57d53e82225
docs
python
python_stdtypes
311
170
Providing keyword arguments as in the first example only works for keys that are valid Python identifiers. Otherwise, any valid keys can be used. These are the operations that dictionaries support (and therefore, custom mapping types should support too): list(d) : Return a list of all the ke...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
29cd6469-bb68-5177-98c3-6a3f6ef52807
docs
python
python_stdtypes
311
171
`__missing__()` is not defined, [`KeyError`](exceptions.html#KeyError "KeyError") is raised. `__missing__()` must be a method; it cannot be an instance variable: ```None >>> class Counter(dict): ... def __missing__(self, key): ... return 0 >>> c = Cou...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
99306b92-7cdb-5f8e-a59f-db705383744d
docs
python
python_stdtypes
311
172
: Equivalent to `not key in d`. iter(d) : Return an iterator over the keys of the dictionary. This is a shortcut for `iter(d.keys())`. clear()[¶](#dict.clear "Link to this definition") : Remove all items from the dictionary. copy()[¶](#dict.copy "Link to this definition") : ...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
9da0a2f9-59a6-57b2-b6c8-3b50f14798c1
docs
python
python_stdtypes
311
173
: Return the value for *key* if *key* is in the dictionary, else *default*. If *default* is not given, it defaults to `None`, so that this method never raises a [`KeyError`](exceptions.html#KeyError "KeyError"). items()[¶](#dict.items "Link to this definition") : Return a new view of th...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
9e760990-c64b-5b26-a0b0-b68f43a8ca0a
docs
python
python_stdtypes
311
174
: Remove and return a `(key, value)` pair from the dictionary. Pairs are returned in LIFO order. [`popitem()`](#dict.popitem "dict.popitem") is useful to destructively iterate over a dictionary, as often used in set algorithms. If the dictionary is empty, calling [`popitem()`](#di...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
640170ee-77bd-57ef-9c19-7307a27521b8
docs
python
python_stdtypes
311
175
update([*other*])[¶](#dict.update "Link to this definition") : Update the dictionary with the key/value pairs from *other*, overwriting existing keys. Return `None`. [`update()`](#dict.update "dict.update") accepts either another dictionary object or an iterable of key/value pairs (as...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
e8676a20-1608-5d52-9932-8c0562627685
docs
python
python_stdtypes
311
176
: Create a new dictionary with the merged keys and values of *d* and *other*, which must both be dictionaries. The values of *other* take priority when *d* and *other* share keys. New in version 3.9. d |= other : Update the dictionary *d* with keys and values from *other*, whic...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
b3162a0f-d504-5049-ae29-4a36778588b8
docs
python
python_stdtypes
311
177
{'one': 1, 'two': 2, 'three': 3, 'four': 4} >>> list(d) ['one', 'two', 'three', 'four'] >>> list(d.values()) [1, 2, 3, 4] >>> d["one"] = 42 >>> d {'one': 42, 'two': 2, 'three': 3, 'four': 4} >>> del d["two"] >>> d["two"] = None >>> d {'one': 42, 'three': 3, 'four': 4, 'tw...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
50d91033-89c5-5953-b740-872f278534f4
docs
python
python_stdtypes
311
178
[`types.MappingProxyType`](types.html#types.MappingProxyType "types.MappingProxyType") can be used to create a read-only view of a [`dict`](#dict "dict"). ### Dictionary view objects[¶](#dictionary-view-objects "Link to this heading") The objects returned by [`dict.keys()`](#dict.keys "dict.keys"), [`dict.values()`](...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
c2aa852b-79c2-5682-909e-613679388e93
docs
python
python_stdtypes
311
179
using [`zip()`](functions.html#zip "zip"): `pairs = zip(d.values(), d.keys())`. Another way to create the same list is `pairs = [(v, k) for (k, v) in d.items()]`. Iterating views while adding or deleting entries in the dictionary may raise a [`RuntimeError`](exceptions.html#RuntimeError "RuntimeError")...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
0e0b0ef4-e8e8-5477-aad8-4ae6042b9288
docs
python
python_stdtypes
311
180
New in version 3.10. Keys views are set-like since their entries are unique and [hashable](../glossary.html#term-hashable). If all values are hashable, so that `(key, value)` pairs are unique and hashable, then the items view is also set-like. (Values views are not treated as set-like since the entries are general...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
a804ca1f-6677-5098-9803-97dfd992b9c4
docs
python
python_stdtypes
311
181
>>> del dishes['eggs'] >>> del dishes['sausage'] >>> list(keys) ['bacon', 'spam'] >>> # set operations >>> keys & {'eggs', 'bacon', 'salad'} {'bacon'} >>> keys ^ {'sausage', 'juice'} == {'juice', 'sausage', 'bacon', 'spam'} True >>> keys | ['juice', 'juice', 'juice'] == {'bacon', 'spam', 'juice'} True >>> # get back ...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
d17b6fda-f67a-596a-b5c6-cc509bdd10bb
docs
python
python_stdtypes
311
182
: Enter the runtime context and return either this object or another object related to the runtime context. The value returned by this method is bound to the identifier in the `as` clause of [`with`](../reference/compound_stmts.html#with) statements using this context manager. An example of a context...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
d83a3595-22e0-5497-aa89-d50b8b3145e0
docs
python
python_stdtypes
311
183
of the [`with`](../reference/compound_stmts.html#with) statement without affecting code outside the `with` statement. contextmanager.\_\_exit\_\_(*exc\_type*, *exc\_val*, *exc\_tb*)[¶](#contextmanager.__exit__ "Link to this definition") : Exit the runtime context and return a Boolean flag indicating if any e...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
57db9826-b8d0-5df2-ae06-ae5f7c811fd6
docs
python
python_stdtypes
311
184
during execution of this method will replace any exception that occurred in the body of the `with` statement. The exception passed in should never be reraised explicitly - instead, this method should return a false value to indicate that the method completed successfully and does not want to suppre...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
f9f3d217-2b19-5fbf-bd8d-7d753074ae60
docs
python
python_stdtypes
311
185
Python’s [generator](../glossary.html#term-generator)s and the [`contextlib.contextmanager`](contextlib.html#contextlib.contextmanager "contextlib.contextmanager") decorator provide a convenient way to implement these protocols. If a generator function is decorated with the [`contextlib.contextmanager`](contextlib.html...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
880ec009-cf8d-56c2-a4c9-e81945d2a96b
docs
python
python_stdtypes
311
186
## Type Annotation Types — [Generic Alias](#types-genericalias), [Union](#types-union)[¶](#type-annotation-types-generic-alias-union "Link to this heading") The core built-in types for [type annotations](../glossary.html#term-annotation) are [Generic Alias](#types-genericalias) and [Union](#types-union). ### Generic ...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
99a1df16-b46c-51f5-b17d-8f0cfbce5f0c
docs
python
python_stdtypes
311
187
the special method [`__class_getitem__()`](../reference/datamodel.html#object.__class_getitem__ "object.__class_getitem__"). A `GenericAlias` object acts as a proxy for a [generic type](../glossary.html#term-generic-type), implementing *parameterized generics*. For a container class, the argument(s) supplied to a [su...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
96785117-e449-54bf-87a5-976c45ed23e6
docs
python
python_stdtypes
311
188
example, [`regular expressions`](re.html#module-re "re: Regular expression operations.") can be used on both the [`str`](#str "str") data type and the [`bytes`](#bytes "bytes") data type: * If `x = re.search('foo', 'foo')`, `x` will be a [re.Match](re.html#match-objects) object where the return values of `x.group(...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
9093ce9c-9a44-5e5f-a6f5-66a4c4404950
docs
python
python_stdtypes
311
189
objects directly. T[X, Y, ...] : Creates a `GenericAlias` representing a type `T` parameterized by types *X*, *Y*, and more depending on the `T` used. For example, a function expecting a [`list`](#list "list") containing [`float`](functions.html#float "float") elements: ```None def average(value...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
3381c07e-a065-5e71-bdab-b9e86d7ff734
docs
python
python_stdtypes
311
190
`GenericAlias` types for their second argument: ```None >>> isinstance([1, 2], list[str]) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: isinstance() argument 2 cannot be a parameterized generic ``` The Python runtime does not enforce [type annotations](../glossary.html#term-annot...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
b19ce2e0-583f-534a-a221-43db27c87691
docs
python
python_stdtypes
311
191
'list[int]' ``` The [`__getitem__()`](../reference/datamodel.html#object.__getitem__ "object.__getitem__") method of generic containers will raise an exception to disallow mistakes like `dict[str][str]`: ```None >>> dict[str][str] Traceback (most recent call last): ... TypeError: dict[str] is not a generic class ``...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
d92ebaa4-2f8b-52bd-ac11-c10221ef22f6
docs
python
python_stdtypes
311
192
* [`type`](functions.html#type "type") * [`collections.deque`](collections.html#collections.deque "collections.deque") * [`collections.defaultdict`](collections.html#collections.defaultdict "collections.defaultdict") * [`collections.OrderedDict`](collections.html#collections.OrderedDict "collections.OrderedDict") * [`c...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
81f115e2-a3a1-5e8b-89ab-9e7bf1c52d1b
docs
python
python_stdtypes
311
193
* [`collections.abc.AsyncGenerator`](collections.abc.html#collections.abc.AsyncGenerator "collections.abc.AsyncGenerator") * [`collections.abc.Iterable`](collections.abc.html#collections.abc.Iterable "collections.abc.Iterable") * [`collections.abc.Iterator`](collections.abc.html#collections.abc.Iterator "collections.ab...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
da3a98ad-49bd-5483-ba44-795b6d0e7b00
docs
python
python_stdtypes
311
194
* [`collections.abc.MutableSet`](collections.abc.html#collections.abc.MutableSet "collections.abc.MutableSet") * [`collections.abc.Mapping`](collections.abc.html#collections.abc.Mapping "collections.abc.Mapping") * [`collections.abc.MutableMapping`](collections.abc.html#collections.abc.MutableMapping "collections.abc.M...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
39c00a68-397f-57dc-99c5-9b5732b86aa6
docs
python
python_stdtypes
311
195
* [`collections.abc.ValuesView`](collections.abc.html#collections.abc.ValuesView "collections.abc.ValuesView") * [`contextlib.AbstractContextManager`](contextlib.html#contextlib.AbstractContextManager "contextlib.AbstractContextManager") * [`contextlib.AbstractAsyncContextManager`](contextlib.html#contextlib.AbstractAs...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
34473cba-c18f-5fd4-99e3-125d4de5370a
docs
python
python_stdtypes
311
196
* [re.Match](re.html#match-objects) * [`shelve.BsdDbShelf`](shelve.html#shelve.BsdDbShelf "shelve.BsdDbShelf") * [`shelve.DbfilenameShelf`](shelve.html#shelve.DbfilenameShelf "shelve.DbfilenameShelf") * [`shelve.Shelf`](shelve.html#shelve.Shelf "shelve.Shelf") * [`types.MappingProxyType`](types.html#types.MappingProxyT...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
be8ed503-f484-5904-a3ff-6e6822051541
docs
python
python_stdtypes
311
197
: This attribute points at the non-parameterized generic class: ```None >>> list[int].__origin__ <class 'list'> ``` genericalias.\_\_args\_\_[¶](#genericalias.__args__ "Link to this definition") : This attribute is a [`tuple`](#tuple "tuple") (possibly of length 1) of generic types passed to t...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
5007b694-42d0-58e0-9824-8292fe7c6bee
docs
python
python_stdtypes
311
198
have correct `__parameters__` after substitution because [`typing.ParamSpec`](typing.html#typing.ParamSpec "typing.ParamSpec") is intended primarily for static type checking. genericalias.\_\_unpacked\_\_[¶](#genericalias.__unpacked__ "Link to this definition") : A boolean that is true if the alias has been ...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
9e62bdfa-f388-5f62-b7a7-b1e7b380d546
docs
python
python_stdtypes
311
199
[Generics](typing.html#generics), [user-defined generics](typing.html#user-defined-generics) and [`typing.Generic`](typing.html#typing.Generic "typing.Generic") : Documentation on how to implement generic classes that can be parameterized at runtime and understood by static type-checkers. New in version 3.9. ##...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
a05e29dc-3ee5-5b9f-832e-51148d9b62ab
docs
python
python_stdtypes
311
200
```None def square(number: int | float) -> int | float: return number ** 2 ``` Note The `|` operand cannot be used at runtime to define unions where one or more members is a forward reference. For example, `int | "Foo"`, where `"Foo"` is a reference to a class not yet defined, will...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
03a27e26-fe58-5365-b25a-2096688183db
docs
python
python_stdtypes
311
201
* Optional types can be spelled as a union with `None`: ```None str | None == typing.Optional[str] ``` isinstance(obj, union\_object) issubclass(obj, union\_object) : Calls to [`isinstance()`](functions.html#isinstance "isinstance") and [`issubclass()`](functions.html#issubclass "issubclass")...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
7e7d310c-c0a7-5ca6-b596-c3801cb8b0e2
docs
python
python_stdtypes
311
202
instantiated from the type: ```None >>> import types >>> isinstance(int | str, types.UnionType) True >>> types.UnionType() Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: cannot create 'types.UnionType' instances ``` Note The `__or__()` method for type objects was added to support...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
8bc6eedd-ae66-5f76-b756-88e88c8bdce1
docs
python
python_stdtypes
311
203
### Modules[¶](#modules "Link to this heading") The only special operation on a module is attribute access: `m.name`, where *m* is a module and *name* accesses a name defined in *m*’s symbol table. Module attributes can be assigned to. (Note that the [`import`](../reference/simple_stmts.html#import) statement is not, ...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
3b656cb0-794d-5f0b-8a10-f642839eb6fc
docs
python
python_stdtypes
311
204
`m.__dict__ = {}`). Modifying [`__dict__`](#object.__dict__ "object.__dict__") directly is not recommended. Modules built into the interpreter are written like this: `<module 'sys' (built-in)>`. If loaded from a file, they are written as `<module 'os' from '/usr/local/lib/pythonX.Y/os.pyc'>`. ### Classes and Class In...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
407cceb1-5fec-5dad-9a1a-d54b007275b7
docs
python
python_stdtypes
311
205
See [Function definitions](../reference/compound_stmts.html#function) for more information. ### Methods[¶](#methods "Link to this heading") Methods are functions that are called using the attribute notation. There are two flavors: [built-in methods](../reference/datamodel.html#builtin-methods) (such as `append()` on ...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
00e54a11-afe7-5f81-a869-79ac923dd702
docs
python
python_stdtypes
311
206
the function implementing the method. Calling `m(arg-1, arg-2, ..., arg-n)` is completely equivalent to calling `m.__func__(m.__self__, arg-1, arg-2, ..., arg-n)`. Like [function objects](../reference/datamodel.html#user-defined-funcs), bound method objects support getting arbitrary attributes. However, since method a...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
21ae5c64-aed9-5ef2-b707-cac68e8639a7
docs
python
python_stdtypes
311
207
AttributeError: 'method' object has no attribute 'whoami' >>> c.method.__func__.whoami = 'my name is method' >>> c.method.whoami 'my name is method' ``` See [Instance methods](../reference/datamodel.html#instance-methods) for more information. ### Code Objects[¶](#code-objects "Link to this heading") Code objects ar...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
f27bae19-8907-5b78-bc89-33b6183e9b88
docs
python
python_stdtypes
311
208
Accessing [`__code__`](../reference/datamodel.html#function.__code__ "function.__code__") raises an [auditing event](sys.html#auditing) `object.__getattr__` with arguments `obj` and `"__code__"`. A code object can be executed or evaluated by passing it (instead of a source string) to the [`exec()`](functions.html#exec...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
7a876896-2fc4-542d-a5b3-3b4bca1a15c1
docs
python
python_stdtypes
311
209
### The Null Object[¶](#the-null-object "Link to this heading") This object is returned by functions that don’t explicitly return a value. It supports no special operations. There is exactly one null object, named `None` (a built-in name). `type(None)()` produces the same singleton. It is written as `None`. ### The ...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
c3cd321a-d9b7-550a-9709-a2d08f16ef9a
docs
python
python_stdtypes
311
210
asked to operate on types they don’t support. See [Comparisons](../reference/expressions.html#comparisons) for more information. There is exactly one [`NotImplemented`](constants.html#NotImplemented "NotImplemented") object. `type(NotImplemented)()` produces the singleton instance. It is written as `NotImplemented`. ...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
831470c6-75cc-559a-9a24-e9c867b86fe8
docs
python
python_stdtypes
311
211
### Internal Objects[¶](#internal-objects "Link to this heading") See [The standard type hierarchy](../reference/datamodel.html#types) for this information. It describes [stack frame objects](../reference/datamodel.html#frame-objects), [traceback objects](../reference/datamodel.html#traceback-objects), and slice objec...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
0e4de27f-28fb-50aa-99dc-3186b404023c
docs
python
python_stdtypes
311
212
definition.\_\_name\_\_[¶](#definition.__name__ "Link to this definition") : The name of the class, function, method, descriptor, or generator instance. definition.\_\_qualname\_\_[¶](#definition.__qualname__ "Link to this definition") : The [qualified name](../glossary.html#term-qualified-name) of the class, ...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
2214d3e4-00e8-513c-ab1b-446fd797130e
docs
python
python_stdtypes
311
213
: Each class keeps a list of weak references to its immediate subclasses. This method returns a list of all those references still alive. The list is in definition order. Example: ```None >>> int.__subclasses__() [<class 'bool'>, <enum 'IntEnum'>, <flag 'IntFlag'>, <class 're._constants._NamedInt...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
e7c9c1e2-6bd2-579a-a396-4608dbb0f2a1
docs
python
python_stdtypes
311
214
a string to a binary integer or a binary integer to a string in linear time, *unless* the base is a power of 2. Even the best known algorithms for base 10 have sub-quadratic complexity. Converting a large value such as `int('1' * 500_000)` can take over a second on a fast CPU. Limiting conversion size offers a practic...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
ea2dfdb0-7cc9-5c55-983a-252274c1902e
docs
python
python_stdtypes
311
215
ValueError: Exceeds the limit (4300 digits) for integer string conversion: value has 5432 digits; use sys.set_int_max_str_digits() to increase the limit >>> i = int('2' * 4300) >>> len(str(i)) 4300 >>> i_squared = i*i >>> len(str(i_squared)) Traceback (most recent call last): ... ValueError: Exceeds the limit (4300 dig...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
569c2563-780d-5efd-b60e-fd241ea69034
docs
python
python_stdtypes
311
216
>>> msg = int('578966293710682886880994035146873798396722250538762761564' ... '9252925514383915483333812743580549779436104706260696366600' ... '571186405732').to_bytes(53, 'big') ... ``` New in version 3.11. ### Affected APIs[¶](#affected-apis "Link to this heading") The limitation only applies t...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
3e3bb397-1efa-59de-a2d2-7daaad86e953
docs
python
python_stdtypes
311
217
* [`hex()`](functions.html#hex "hex"), [`oct()`](functions.html#oct "oct"), [`bin()`](functions.html#bin "bin"). * [Format Specification Mini-Language](string.html#formatspec) for hex, octal, and binary numbers. * [`str`](#str "str") to [`float`](functions.html#float "float"). * [`str`](#str "str") to [`decimal.Decimal...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
fb3d62a5-a872-5d90-a9e9-ab022fb35ad8
docs
python
python_stdtypes
311
218
[`PYTHONINTMAXSTRDIGITS`](../using/cmdline.html#envvar-PYTHONINTMAXSTRDIGITS) or [`-X int_max_str_digits`](../using/cmdline.html#cmdoption-X). If both the env var and the `-X` option are set, the `-X` option takes precedence. A value of *-1* indicates that both were unset, thus a value of [`sys.int_info.default...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
cac0d205-b6d8-5fba-97b9-43adce4b75ab
docs
python
python_stdtypes
311
219
Information about the default and minimum can be found in [`sys.int_info`](sys.html#sys.int_info "sys.int_info"): * [`sys.int_info.default_max_str_digits`](sys.html#sys.int_info "sys.int_info") is the compiled-in default limit. * [`sys.int_info.str_digits_check_threshold`](sys.html#sys.int_info "sys.int_info") is th...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
1a90583a-aa6b-5bc3-91e9-3f3d915c7158
docs
python
python_stdtypes
311
220
Test your application thoroughly if you use a low limit. Ensure your tests run with the limit set early via the environment or flag so that it applies during startup and even during any installation step that may invoke Python to precompile `.py` sources to `.pyc` files. ### Recommended configuration[¶](#recommended-c...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
1c82afbf-d06a-59f8-a0a4-c4a85fc35453
docs
python
python_stdtypes
311
221
... sys.set_int_max_str_digits(upper_bound) ... elif current_limit < lower_bound: ... sys.set_int_max_str_digits(lower_bound) ``` If you need to disable it entirely, set it to `0`. Footnotes [[1](#id1)] Additional information on these special methods may be found in the Python Reference Manual (...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
440126cb-8173-5bc5-b637-1272ec2b07b4
docs
python
python_stdtypes
312
0
# Built-in Types¶ Source: https://docs.python.org/3.12/library/stdtypes.html Version: 3.12 The following sections describe the standard types that are built into the interpreter. The principal built-in types are numerics, sequences, mappings, classes, instances and exceptions. Some collection classes are mutable. T...
large_dataset/raw/docs/python/stdtypes/stdtypes_312.md
90b89d3e-7542-5f17-a0c7-68bc5b282560
docs
python
python_stdtypes
312
1
## Truth Value Testing[¶](#truth-value-testing "Link to this heading") Any object can be tested for truth value, for use in an [`if`](../reference/compound_stmts.html#if) or [`while`](../reference/compound_stmts.html#while) condition or as operand of the Boolean operations below. By default, an object is considered t...
large_dataset/raw/docs/python/stdtypes/stdtypes_312.md
2f546a92-0ab2-5b52-98d8-8e47dd56cb23
docs
python
python_stdtypes
312
2
or `False` for false and `1` or `True` for true, unless otherwise stated. (Important exception: the Boolean operations `or` and `and` always return one of their operands.) ## Boolean Operations — `and`, `or`, `not`[¶](#boolean-operations-and-or-not "Link to this heading") These are the Boolean operations, ordered by ...
large_dataset/raw/docs/python/stdtypes/stdtypes_312.md
6a3f575c-5c57-540b-ba45-2e586c61b95c
docs
python
python_stdtypes
312
3
## Comparisons[¶](#comparisons "Link to this heading") There are eight comparison operations in Python. They all have the same priority (which is higher than that of the Boolean operations). Comparisons can be chained arbitrarily; for example, `x < y <= z` is equivalent to `x < y and y <= z`, except that *y* is evalua...
large_dataset/raw/docs/python/stdtypes/stdtypes_312.md
016913bc-446e-5c9f-9c55-252d3665df56
docs
python
python_stdtypes
312
4
operators are only defined where they make sense; for example, they raise a [`TypeError`](exceptions.html#TypeError "TypeError") exception when one of the arguments is a complex number. Non-identical instances of a class normally compare as non-equal unless the class defines the [`__eq__()`](../reference/datamodel.htm...
large_dataset/raw/docs/python/stdtypes/stdtypes_312.md
454bcc6e-8cc4-52e7-9890-0344adb271b4
docs
python
python_stdtypes
312
5
[`__eq__()`](../reference/datamodel.html#object.__eq__ "object.__eq__") are sufficient, if you want the conventional meanings of the comparison operators). The behavior of the [`is`](../reference/expressions.html#is) and [`is not`](../reference/expressions.html#is-not) operators cannot be customized; also they can be ...
large_dataset/raw/docs/python/stdtypes/stdtypes_312.md
5d8ab33e-e554-53b3-82b1-5e5730a343de
docs
python
python_stdtypes
312
6
numbers*, and *complex numbers*. In addition, Booleans are a subtype of integers. Integers have unlimited precision. Floating-point numbers are usually implemented using double in C; information about the precision and internal representation of floating-point numbers for the machine on which your program is running is...
large_dataset/raw/docs/python/stdtypes/stdtypes_312.md
2e1e1ad6-ceb1-5d10-b518-b07404f2405a
docs
python
python_stdtypes
312
7
numbers) yield integers. Numeric literals containing a decimal point or an exponent sign yield floating-point numbers. Appending `'j'` or `'J'` to a numeric literal yields an imaginary number (a complex number with a zero real part) which you can add to an integer or float to get a complex number with real and imaginar...
large_dataset/raw/docs/python/stdtypes/stdtypes_312.md
3b4152a1-80ca-54de-a0fb-150c6522731d
docs
python
python_stdtypes
312
8
the operations, see [Operator precedence](../reference/expressions.html#operator-summary)): | Operation | Result | Notes | Full documentation | | --- | --- | --- | --- | | `x + y` | sum of *x* and *y* | | | | `x - y` | difference of *x* and *y* | | | | `x * y` | product of *x* and *y* | | | | `x / y` | quotient ...
large_dataset/raw/docs/python/stdtypes/stdtypes_312.md
dde9704e-b534-583a-80ba-ba3383c061db
docs
python
python_stdtypes
312
9
| `divmod(x, y)` | the pair `(x // y, x % y)` | (2) | [`divmod()`](functions.html#divmod "divmod") | | `pow(x, y)` | *x* to the power *y* | (5) | [`pow()`](functions.html#pow "pow") | | `x ** y` | *x* to the power *y* | (5) | | Notes: 1. Also referred to as integer division. For operands of type [`int`](functions.ht...
large_dataset/raw/docs/python/stdtypes/stdtypes_312.md
b7359497-f4d3-5549-938e-acb1f5580057
docs
python
python_stdtypes
312
10
fractional part. See functions [`math.floor()`](math.html#math.floor "math.floor") and [`math.ceil()`](math.html#math.ceil "math.ceil") for alternative conversions. 4. float also accepts the strings “nan” and “inf” with an optional prefix “+” or “-” for Not a Number (NaN) and positive or negative infinity. 5. ...
large_dataset/raw/docs/python/stdtypes/stdtypes_312.md
261df10a-f536-5f71-bcce-9288d9530c1b
docs
python
python_stdtypes
312
11
| [`math.trunc(x)`](math.html#math.trunc "math.trunc") | *x* truncated to [`Integral`](numbers.html#numbers.Integral "numbers.Integral") | | [`round(x[, n])`](functions.html#round "round") | *x* rounded to *n* digits, rounding half to even. If *n* is omitted, it defaults to 0. | | [`math.floor(x)`](math.html#math.floor...
large_dataset/raw/docs/python/stdtypes/stdtypes_312.md
17d0dbb5-2e5c-5efb-8d58-e90290317858
docs
python
python_stdtypes
312
12
operations is calculated as though carried out in two’s complement with an infinite number of sign bits. The priorities of the binary bitwise operations are all lower than the numeric operations and higher than the comparisons; the unary operation `~` has the same priority as the other unary numeric operations (`+` an...
large_dataset/raw/docs/python/stdtypes/stdtypes_312.md
c88c8f49-6f36-5dce-913a-ecba11ff6732
docs
python
python_stdtypes
312
13
3. A right shift by *n* bits is equivalent to floor division by `pow(2, n)`. 4. Performing these calculations with at least one extra sign extension bit in a finite two’s complement representation (a working bit-width of `1 + max(x.bit_length(), y.bit_length())` or more) is sufficient to get the same result as...
large_dataset/raw/docs/python/stdtypes/stdtypes_312.md
cec7df39-9dcb-53a7-9fd5-454a467a9cd4
docs
python
python_stdtypes
312
14
More precisely, if `x` is nonzero, then `x.bit_length()` is the unique positive integer `k` such that `2**(k-1) <= abs(x) < 2**k`. Equivalently, when `abs(x)` is small enough to have a correctly rounded logarithm, then `k = 1 + int(log(abs(x), 2))`. If `x` is zero, then `x.bit_length()` returns `0`....
large_dataset/raw/docs/python/stdtypes/stdtypes_312.md
07082db1-b7b4-5839-98ed-9de5bda08eb2
docs
python
python_stdtypes
312
15
return bin(self).count("1") ``` Added in version 3.10. int.to\_bytes(*length=1*, *byteorder='big'*, *\**, *signed=False*)[¶](#int.to_bytes "Link to this definition") : Return an array of bytes representing an integer. ```None >>> (1024).to_bytes(2, byteorder='big') b'\x04\x00' >>> (...
large_dataset/raw/docs/python/stdtypes/stdtypes_312.md