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
4863c013-8b0d-5231-ac61-30a7d7ca7f43
docs
python
python_stdtypes
310
159
*class* `frozenset`([*iterable*])[¶](#frozenset "Permalink to this definition") : Return a new set or frozenset object whose elements are taken from *iterable*. The elements of a set must be [hashable](../glossary.html#term-hashable). To represent sets of sets, the inner sets must be [`frozenset`](#frozenset ...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
bdc34764-d0b9-5ed4-bd2f-abf308926f1b
docs
python
python_stdtypes
310
160
`isdisjoint`(*other*)[¶](#frozenset.isdisjoint "Permalink to this definition") : Return `True` if the set has no elements in common with *other*. Sets are disjoint if and only if their intersection is the empty set. `issubset`(*other*)[¶](#frozenset.issubset "Permalink to this definition") `...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
b2ddfc87-9fbe-50df-b0d7-63ce7ceeab0e
docs
python
python_stdtypes
310
161
`intersection`(*\*others*)[¶](#frozenset.intersection "Permalink to this definition") `set & other & ...` : Return a new set with elements common to the set and all others. `difference`(*\*others*)[¶](#frozenset.difference "Permalink to this definition") `set - other - ...` : Return a new...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
a28ac6da-96f2-5aef-a135-c0bdc62270b3
docs
python
python_stdtypes
310
162
[`difference()`](#frozenset.difference "frozenset.difference"), [`symmetric_difference()`](#frozenset.symmetric_difference "frozenset.symmetric_difference"), [`issubset()`](#frozenset.issubset "frozenset.issubset"), and [`issuperset()`](#frozenset.issuperset "frozenset.issuperset") methods will accept any itera...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
b984b032-cb70-53e8-b1c0-b48727d4f870
docs
python
python_stdtypes
310
163
is a proper superset of the second set (is a superset, but is not equal). Instances of [`set`](#set "set") are compared to instances of [`frozenset`](#frozenset "frozenset") based on their members. For example, `set('abc') == frozenset('abc')` returns `True` and so does `set('abc') in set([frozenset('a...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
e97856ce-6cc2-513b-b272-d6f1118baaca
docs
python
python_stdtypes
310
164
return the type of the first operand. For example: `frozenset('ab') | set('bc')` returns an instance of [`frozenset`](#frozenset "frozenset"). The following table lists operations available for [`set`](#set "set") that do not apply to immutable instances of [`frozenset`](#frozenset "frozenset"): `...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
6a375883-626a-5273-8909-7b9128d27c2f
docs
python
python_stdtypes
310
165
: Update the set, keeping only elements found in either set, but not in both. `add`(*elem*)[¶](#frozenset.add "Permalink to this definition") : Add element *elem* to the set. `remove`(*elem*)[¶](#frozenset.remove "Permalink to this definition") : Remove element *elem* from the set. Raises [`...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
d1d483f7-08bb-586c-a40a-ce7766667af6
docs
python
python_stdtypes
310
166
[`intersection_update()`](#frozenset.intersection_update "frozenset.intersection_update"), [`difference_update()`](#frozenset.difference_update "frozenset.difference_update"), and [`symmetric_difference_update()`](#frozenset.symmetric_difference_update "frozenset.symmetric_difference_update") methods will accep...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
25918fa5-8e8d-562a-a815-a9964128cddc
docs
python
python_stdtypes
310
167
[`list`](#list "list"), [`set`](#set "set"), and [`tuple`](#tuple "tuple") classes, and the [`collections`](collections.html#module-collections "collections: Container datatypes") module.) A dictionary’s keys are *almost* arbitrary values. Values that are not [hashable](../glossary.html#term-hashable), that is, values...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
1b64a1ad-d775-5582-8be6-8a705217c253
docs
python
python_stdtypes
310
168
`{'jack': 4098, 'sjoerd': 4127}` or `{4098: 'jack', 4127: 'sjoerd'}` * Use a dict comprehension: `{}`, `{x: x ** 2 for x in range(10)}` * Use the type constructor: `dict()`, `dict([('foo', 100), ('bar', 200)])`, `dict(foo=100, bar=200)` If no positional argument is given, an empty dictionary is...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
cf7bd88d-5faa-5631-88c6-93ab6f56a343
docs
python
python_stdtypes
310
169
added to the dictionary created from the positional argument. If a key being added is already present, the value from the keyword argument replaces the value from the positional argument. To illustrate, the following examples all return a dictionary equal to `{"one": 1, "two": 2, "three": 3}`: ...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
373c588a-ef7c-5603-89e8-4547a38438b0
docs
python
python_stdtypes
310
170
: Return a list of all the keys used in the dictionary *d*. `len(d)` : Return the number of items in the dictionary *d*. `d[key]` : Return the item of *d* with key *key*. Raises a [`KeyError`](exceptions.html#KeyError "KeyError") if *key* is not in the map. If a subclass of ...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
38b34228-e21a-5ab1-993a-b5bbf6f4e69a
docs
python
python_stdtypes
310
171
>>> c['red'] += 1 >>> c['red'] 1 ``` The example above shows part of the implementation of [`collections.Counter`](collections.html#collections.Counter "collections.Counter"). A different `__missing__` method is used by [`collections.defaultdict`](collections.htm...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
ad258bad-d088-534c-998d-50622e3b42f6
docs
python
python_stdtypes
310
172
: Return a shallow copy of the dictionary. *classmethod* `fromkeys`(*iterable*[, *value*])[¶](#dict.fromkeys "Permalink to this definition") : Create a new dictionary with keys from *iterable* and values set to *value*. [`fromkeys()`](#dict.fromkeys "dict.fromkeys") is a class method that retu...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
d5569bf7-abf5-54f1-9e95-246f954969be
docs
python
python_stdtypes
310
173
: Return a new view of the dictionary’s items (`(key, value)` pairs). See the [documentation of view objects](#dict-views). `keys`()[¶](#dict.keys "Permalink to this definition") : Return a new view of the dictionary’s keys. See the [documentation of view objects](#dict-views). `po...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
212fc5f4-e451-510b-95f6-6368cc9b8501
docs
python
python_stdtypes
310
174
[`popitem()`](#dict.popitem "dict.popitem") raises a [`KeyError`](exceptions.html#KeyError "KeyError"). Changed in version 3.7: LIFO order is now guaranteed. In prior versions, [`popitem()`](#dict.popitem "dict.popitem") would return an arbitrary key/value pair. `reversed(d)` : Retur...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
c6a2853b-e786-5b69-b024-94639d2aeb44
docs
python
python_stdtypes
310
175
key/value pairs (as tuples or other iterables of length two). If keyword arguments are specified, the dictionary is then updated with those key/value pairs: `d.update(red=1, blue=2)`. `values`()[¶](#dict.values "Permalink to this definition") : Return a new view of the dictionary’s va...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
a14a4a68-3cf9-530d-b6fb-9adbe29a3fa5
docs
python
python_stdtypes
310
176
either a [mapping](../glossary.html#term-mapping) or an [iterable](../glossary.html#term-iterable) of key/value pairs. The values of *other* take priority when *d* and *other* share keys. New in version 3.9. Dictionaries compare equal if and only if they have the same `(key, value)` pa...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
d041cb29-f882-5b1e-997c-74f1f90388ac
docs
python
python_stdtypes
310
177
Changed in version 3.7: Dictionary order is guaranteed to be insertion order. This behavior was an implementation detail of CPython from 3.6. Dictionaries and dictionary views are reversible. ```None >>> d = {"one": 1, "two": 2, "three": 3, "four": 4} >>> d {'one': 1, 'two': 2, 'three': 3,...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
6e92b928-e28a-5677-ab27-65b1f458e360
docs
python
python_stdtypes
310
178
[`dict.items()`](#dict.items "dict.items") are *view objects*. They provide a dynamic view on the dictionary’s entries, which means that when the dictionary changes, the view reflects these changes. Dictionary views can be iterated over to yield their respective data, and support membership tests: `len(dictview)` : ...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
4e161f6f-dc17-5a6f-ae01-5091b391be52
docs
python
python_stdtypes
310
179
Changed in version 3.7: Dictionary order is guaranteed to be insertion order. `x in dictview` : Return `True` if *x* is in the underlying dictionary’s keys, values or items (in the latter case, *x* should be a `(key, value)` tuple). `reversed(dictview)` : Return a reverse iterator over the keys, values or...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
1e4eeb90-6597-55c9-893c-fd6e8e3cdbd6
docs
python
python_stdtypes
310
180
since the entries are generally not unique.) For set-like views, all of the operations defined for the abstract base class [`collections.abc.Set`](collections.abc.html#collections.abc.Set "collections.abc.Set") are available (for example, `==`, `<`, or `^`). An example of dictionary view usage: ```None >>> dishes = {...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
62bbc0fe-46c8-5f74-8541-da8d79b088ed
docs
python
python_stdtypes
310
181
>>> values.mapping mappingproxy({'bacon': 1, 'spam': 500}) >>> values.mapping['spam'] 500 ``` ## Context Manager Types[¶](#context-manager-types "Permalink to this headline") Python’s [`with`](../reference/compound_stmts.html#with) statement supports the concept of a runtime context defined by a context manager. This...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
4c28911a-fa8e-57c1-b1da-9fe799766394
docs
python
python_stdtypes
310
182
File objects return themselves from \_\_enter\_\_() to allow [`open()`](functions.html#open "open") to be used as the context expression in a [`with`](../reference/compound_stmts.html#with) statement. An example of a context manager that returns a related object is the one returned by [`decimal.localco...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
34e04853-efec-5f59-9f87-acf7df4f177c
docs
python
python_stdtypes
310
183
body of the [`with`](../reference/compound_stmts.html#with) statement, the arguments contain the exception type, value and traceback information. Otherwise, all three arguments are `None`. Returning a true value from this method will cause the [`with`](../reference/compound_stmts.html#with) statement t...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
abd0750d-c2d2-5c5d-a069-472c985c9837
docs
python
python_stdtypes
310
184
context management code to easily detect whether or not an [`__exit__()`](#contextmanager.__exit__ "contextmanager.__exit__") method has actually failed. Python defines several context managers to support easy thread synchronisation, prompt closure of files or other objects, and simpler manipulation of the act...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
8825eb0a-e204-5e7a-a636-e557dc30e8b9
docs
python
python_stdtypes
310
185
context manager implementing the necessary [`__enter__()`](#contextmanager.__enter__ "contextmanager.__enter__") and [`__exit__()`](#contextmanager.__exit__ "contextmanager.__exit__") methods, rather than the iterator produced by an undecorated generator function. Note that there is no specific slot for any of these m...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
6a0a0337-64b6-5f59-b355-55fef2e65ca7
docs
python
python_stdtypes
310
186
### Generic Alias Type[¶](#generic-alias-type "Permalink to this headline") `GenericAlias` objects are generally created by [subscripting](../reference/expressions.html#subscriptions) a class. They are most often used with [container classes](../reference/datamodel.html#sequence-types), such as [`list`](#list "list") ...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
e0b034ed-4ae2-5a34-a2fa-fe82b8499964
docs
python
python_stdtypes
310
187
argument(s) supplied to a [subscription](../reference/expressions.html#subscriptions) of the class may indicate the type(s) of the elements an object contains. For example, `set[bytes]` can be used in type annotations to signify a [`set`](#set "set") in which all the elements are of type [`bytes`](#bytes "bytes"). For...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
0b128d96-7844-5546-aa4e-74808fc161f4
docs
python
python_stdtypes
310
188
represent this kind of object in type annotations with the `GenericAlias` `re.Match[str]`. * If `y = re.search(b'bar', b'bar')`, (note the `b` for [`bytes`](#bytes "bytes")), `y` will also be an instance of `re.Match`, but the return values of `y.group(0)` and `y[0]` will both be of type [`bytes`](#bytes "byt...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
0f59517a-a690-57f8-b485-0431b13a7342
docs
python
python_stdtypes
310
189
Another example for [mapping](../glossary.html#term-mapping) objects, using a [`dict`](#dict "dict"), which is a generic type expecting two type parameters representing the key type and the value type. In this example, the function expects a `dict` with keys of type [`str`](#str "str") and values of typ...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
b795f7c7-fcc4-509e-8ad0-337e7596081b
docs
python
python_stdtypes
310
190
a container object from a `GenericAlias`, the elements in the container are not checked against their type. For example, the following code is discouraged, but will run without errors: ```None >>> t = list[str] >>> t([1, 2, 3]) [1, 2, 3] ``` Furthermore, parameterized generics erase type parameters during object crea...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
c9f1cf4b-e72f-548a-8970-9d3a85806f7d
docs
python
python_stdtypes
310
191
However, such expressions are valid when [type variables](typing.html#generics) are used. The index must have as many elements as there are type variable items in the `GenericAlias` object’s [`__args__`](#genericalias.__args__ "genericalias.__args__"). ```None >>> from typing import TypeVar >>> Y = TypeVar('Y') >>> di...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
1ce864c0-c2a3-5b88-af0c-e00d26463969
docs
python
python_stdtypes
310
192
* [`collections.Counter`](collections.html#collections.Counter "collections.Counter") * [`collections.ChainMap`](collections.html#collections.ChainMap "collections.ChainMap") * [`collections.abc.Awaitable`](collections.abc.html#collections.abc.Awaitable "collections.abc.Awaitable") * [`collections.abc.Coroutine`](colle...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
81a3381e-af51-5eca-b7fe-02e7fa5fed8d
docs
python
python_stdtypes
310
193
* [`collections.abc.Generator`](collections.abc.html#collections.abc.Generator "collections.abc.Generator") * [`collections.abc.Reversible`](collections.abc.html#collections.abc.Reversible "collections.abc.Reversible") * [`collections.abc.Container`](collections.abc.html#collections.abc.Container "collections.abc.Conta...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
4b70eb02-a7d6-5ac9-a05c-90d492fdfdbd
docs
python
python_stdtypes
310
194
* [`collections.abc.Sequence`](collections.abc.html#collections.abc.Sequence "collections.abc.Sequence") * [`collections.abc.MutableSequence`](collections.abc.html#collections.abc.MutableSequence "collections.abc.MutableSequence") * [`collections.abc.ByteString`](collections.abc.html#collections.abc.ByteString "collect...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
d5b75a01-bfe5-53a2-9303-ecba2e9272d2
docs
python
python_stdtypes
310
195
* [`contextlib.AbstractAsyncContextManager`](contextlib.html#contextlib.AbstractAsyncContextManager "contextlib.AbstractAsyncContextManager") * [`dataclasses.Field`](dataclasses.html#dataclasses.Field "dataclasses.Field") * [`functools.cached_property`](functools.html#functools.cached_property "functools.cached_propert...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
e7d7b889-9467-5aaa-a697-cdb8f9dac9a4
docs
python
python_stdtypes
310
196
* [`shelve.Shelf`](shelve.html#shelve.Shelf "shelve.Shelf") * [`types.MappingProxyType`](types.html#types.MappingProxyType "types.MappingProxyType") * [`weakref.WeakKeyDictionary`](weakref.html#weakref.WeakKeyDictionary "weakref.WeakKeyDictionary") * [`weakref.WeakMethod`](weakref.html#weakref.WeakMethod "weakref.WeakM...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
61583131-22d6-563a-9b49-f41d2d65c46d
docs
python
python_stdtypes
310
197
: This attribute is a [`tuple`](#tuple "tuple") (possibly of length 1) of generic types passed to the original [`__class_getitem__()`](../reference/datamodel.html#object.__class_getitem__ "object.__class_getitem__") of the generic class: ```None >>> dict[str, list[int]].__args__ (<class 'str'>, l...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
3017286c-8454-5374-996b-d35a49e9e670
docs
python
python_stdtypes
310
198
[**PEP 484**](https://www.python.org/dev/peps/pep-0484) - Type Hints : Introducing Python’s framework for type annotations. [**PEP 585**](https://www.python.org/dev/peps/pep-0585) - Type Hinting Generics In Standard Collections : Introducing the ability to natively parameterize standard-library classes, provid...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
d5484087-5d6a-5635-b3c3-589542d2cf02
docs
python
python_stdtypes
310
199
primarily for [type annotations](../glossary.html#term-annotation). The union type expression enables cleaner type hinting syntax compared to [`typing.Union`](typing.html#typing.Union "typing.Union"). `X | Y | ...` : Defines a union object which holds types *X*, *Y*, and so forth. `X | Y` means either X or Y. It...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
ab3bf458-91ec-5409-abfb-d100d54f1a42
docs
python
python_stdtypes
310
200
``` * It is compatible with [`typing.Union`](typing.html#typing.Union "typing.Union"): ```None int | str == typing.Union[int, str] ``` * Optional types can be spelled as a union with `None`: ```None str | None == typing.Optional[str] ``` `isinstance(obj, union_object...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
90246703-cba6-585c-802d-ad2f563adabd
docs
python
python_stdtypes
310
201
[`types.UnionType`](types.html#types.UnionType "types.UnionType") and used for [`isinstance()`](functions.html#isinstance "isinstance") checks. An object cannot be instantiated from the type: ```None >>> import types >>> isinstance(int | str, types.UnionType) True >>> types.UnionType() Traceback (most recent call last...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
69ebcd40-83db-58d2-8f4b-5c3a432181ff
docs
python
python_stdtypes
310
202
## Other Built-in Types[¶](#other-built-in-types "Permalink to this headline") The interpreter supports several other kinds of objects. Most of these support only one or two operations. ### Modules[¶](#modules "Permalink to this headline") The only special operation on a module is attribute access: `m.name`, where *...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
ee264ba2-b584-5d4e-b655-5f5e34515e4d
docs
python
python_stdtypes
310
203
[`__dict__`](#object.__dict__ "object.__dict__") attribute is not possible (you can write `m.__dict__['a'] = 1`, which defines `m.a` to be `1`, but you can’t write `m.__dict__ = {}`). Modifying [`__dict__`](#object.__dict__ "object.__dict__") directly is not recommended. Modules built into the interpreter are written ...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
bf3fdb51-6b50-5b02-ab85-cff5fba0bf33
docs
python
python_stdtypes
310
204
user-defined functions. Both support the same operation (to call the function), but the implementation is different, hence the different object types. See [Function definitions](../reference/compound_stmts.html#function) for more information. ### Methods[¶](#methods "Permalink to this headline") Methods are function...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
e9a4dbe0-f83b-5505-8a2b-0de94b4778d5
docs
python
python_stdtypes
310
205
is completely equivalent to calling `m.__func__(m.__self__, arg-1, arg-2, ..., arg-n)`. Like function objects, bound method objects support getting arbitrary attributes. However, since method attributes are actually stored on the underlying function object (`meth.__func__`), setting method attributes on bound methods ...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
34399f10-cfea-5f2d-bfdb-12f14cb17387
docs
python
python_stdtypes
310
206
See [The standard type hierarchy](../reference/datamodel.html#types) for more information. ### Code Objects[¶](#code-objects "Permalink to this headline") Code objects are used by the implementation to represent “pseudo-compiled” executable Python code such as a function body. They differ from function objects becaus...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
680c96e0-19b9-50f5-9a0b-2e8f38d17949
docs
python
python_stdtypes
310
207
See [The standard type hierarchy](../reference/datamodel.html#types) for more information. ### Type Objects[¶](#type-objects "Permalink to this headline") Type objects represent the various object types. An object’s type is accessed by the built-in function [`type()`](functions.html#type "type"). There are no special...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
db34157b-0091-547d-a17b-74926780d92f
docs
python
python_stdtypes
310
208
### The Ellipsis Object[¶](#the-ellipsis-object "Permalink to this headline") This object is commonly used by slicing (see [Slicings](../reference/expressions.html#slicings)). It supports no special operations. There is exactly one ellipsis object, named [`Ellipsis`](constants.html#Ellipsis "Ellipsis") (a built-in nam...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
14dc4557-ac5b-50ce-9a42-1f1747298dc9
docs
python
python_stdtypes
310
209
### Boolean Values[¶](#boolean-values "Permalink to this headline") Boolean values are the two constant objects `False` and `True`. They are used to represent truth values (although other values can also be considered false or true). In numeric contexts (for example when used as the argument to an arithmetic operator)...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
5ffbb256-c3f0-5677-9eb8-4d54fbc07994
docs
python
python_stdtypes
310
210
## Special Attributes[¶](#special-attributes "Permalink to this headline") The implementation adds a few special read-only attributes to several object types, where they are relevant. Some of these are not reported by the [`dir()`](functions.html#dir "dir") built-in function. `object.``__dict__`[¶](#object.__dict__ "...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
f70408cb-0b47-5bf1-8362-1e8918293a9c
docs
python
python_stdtypes
310
211
: The [qualified name](../glossary.html#term-qualified-name) of the class, function, method, descriptor, or generator instance. New in version 3.3. `class.``__mro__`[¶](#class.__mro__ "Permalink to this definition") : This attribute is a tuple of classes that are considered when looking for base class...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
b7add682-a5c7-5040-bcc2-6e8dda62a0bc
docs
python
python_stdtypes
310
212
## Integer string conversion length limitation[¶](#integer-string-conversion-length-limitation "Permalink to this headline") CPython has a global limit for converting between [`int`](functions.html#int "int") and [`str`](#str "str") to mitigate denial of service attacks. This limit *only* applies to decimal or other n...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
6fda398e-3847-5d88-b399-9810a63b218e
docs
python
python_stdtypes
310
213
Limiting conversion size offers a practical way to avoid [CVE-2020-10735](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-10735). The limit is applied to the number of digit characters in the input or output string when a non-linear conversion algorithm would be involved. Underscores and the sign are not count...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
f0aacd70-d251-5755-acc7-bfb4003b2215
docs
python
python_stdtypes
310
214
ValueError: Exceeds the limit (4300) for integer string conversion: value has 8599 digits; use sys.set_int_max_str_digits() to increase the limit. >>> len(hex(i_squared)) 7144 >>> assert int(hex(i_squared), base=16) == i*i # Hexadecimal is unlimited. ``` The default limit is 4300 digits as provided in [`sys.int_info....
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
13456162-6588-5734-904c-f41d494470e5
docs
python
python_stdtypes
310
215
### Affected APIs[¶](#affected-apis "Permalink to this headline") The limitation only applies to potentially slow conversions between [`int`](functions.html#int "int") and [`str`](#str "str") or [`bytes`](#bytes "bytes"): * `int(string)` with default base 10. * `int(string, base)` for all bases that are not a power o...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
24024392-ddfd-562b-b82a-a2f08139179c
docs
python
python_stdtypes
310
216
* [`str`](#str "str") to [`decimal.Decimal`](decimal.html#decimal.Decimal "decimal.Decimal"). ### Configuring the limit[¶](#configuring-the-limit "Permalink to this headline") Before Python starts up you can use an environment variable or an interpreter command line flag to configure the limit: * [`PYTHONINTMAXSTRDI...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
4cee4270-de1d-5048-88af-dd21c32a7326
docs
python
python_stdtypes
310
217
`sys.int_info.default_max_str_digits` was used during initialization. From code, you can inspect the current limit and set a new one using these [`sys`](sys.html#module-sys "sys: Access system-specific parameters and functions.") APIs: * [`sys.get_int_max_str_digits()`](sys.html#sys.get_int_max_str_digits "sys.get_...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
6c04e460-cc1b-5ceb-afc7-1af3decb4150
docs
python
python_stdtypes
310
218
Setting a low limit *can* lead to problems. While rare, code exists that contains integer constants in decimal in their source that exceed the minimum threshold. A consequence of setting the limit is that Python source code containing decimal integer literals longer than the limit will encounter an error during parsing...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
9d67b578-8f57-5c3e-9c42-e8b528a3f60a
docs
python
python_stdtypes
310
219
### Recommended configuration[¶](#recommended-configuration "Permalink to this headline") The default `sys.int_info.default_max_str_digits` is expected to be reasonable for most applications. If your application requires a different limit, set it from your main entry point using Python version agnostic code as these A...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
02e07751-add5-56c7-a58c-88bbd79e664f
docs
python
python_stdtypes
310
220
Reference Manual ([Basic customization](../reference/datamodel.html#customization)). [2](#id2) : As a consequence, the list `[1, 2]` is considered equal to `[1.0, 2.0]`, and similarly for tuples. [3](#id4) : They must have since the parser can’t tell the type of the operands. 4([1](#id6),[2](#id7),[3](#i...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
625ed4e9-da53-5422-bfd1-6054b079eb8f
docs
python
python_stdtypes
311
0
# Built-in Types¶ Source: https://docs.python.org/3.11/library/stdtypes.html Version: 3.11 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_311.md
d2cba7fd-b570-5f83-863f-19673d71cb14
docs
python
python_stdtypes
311
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_311.md
2d4b7388-fd9e-5bb6-b0b9-b6a7eecfaf72
docs
python
python_stdtypes
311
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_311.md
0210b777-cad9-599f-91a8-57ed5855046b
docs
python
python_stdtypes
311
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_311.md
dfd415f7-d66b-5dc3-b9e8-093b1bbecfb9
docs
python
python_stdtypes
311
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_311.md
0d5b3296-2f4a-5cf0-a612-0c0a514df3f9
docs
python
python_stdtypes
311
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_311.md
bcd55806-8921-508c-b078-513786eb4ac4
docs
python
python_stdtypes
311
6
point 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 runn...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
a27400d5-d872-5a19-9858-f352332a909e
docs
python
python_stdtypes
311
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_311.md
3141d229-f797-5291-9d7b-24c9fc568297
docs
python
python_stdtypes
311
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_311.md
6dbaf416-a5c1-5476-8b3b-6827253525cb
docs
python
python_stdtypes
311
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_311.md
0dc88e94-1d28-55c9-9d75-4794efe31ac7
docs
python
python_stdtypes
311
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_311.md
34260e01-8379-5c9c-94d0-49a787cc14bd
docs
python
python_stdtypes
311
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_311.md
8032282b-b503-53af-bc19-31cf18b65c9e
docs
python
python_stdtypes
311
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_311.md
b506f74b-cd84-5f83-8ad5-96206b7accc6
docs
python
python_stdtypes
311
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_311.md
25e18ac9-bb83-5091-afed-7964a38af144
docs
python
python_stdtypes
311
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_311.md
a3ff4d76-77db-548e-9478-1cc9e9dde6a2
docs
python
python_stdtypes
311
15
return bin(self).count("1") ``` New 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' >>> (10...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
a31d0244-42a0-5c5f-8971-fc30c901052e
docs
python
python_stdtypes
311
16
`"big"`, the most significant byte is at the beginning of the byte array. If *byteorder* is `"little"`, the most significant byte is at the end of the byte array. The *signed* argument determines whether two’s complement is used to represent the integer. If *signed* is `False` and a negative intege...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
2b2e6f2c-b6b7-5d63-a42c-19e71be347cd
docs
python
python_stdtypes
311
17
order = reversed(range(length)) else: raise ValueError("byteorder must be either 'little' or 'big'") return bytes((n >> i*8) & 0xff for i in order) ``` New in version 3.2. Changed in version 3.11: Added default argument values for `length` and `byteorder`. *classm...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
f57e9c02-8180-5b16-a7d9-82091b01f0ac
docs
python
python_stdtypes
311
18
The *byteorder* argument determines the byte order used to represent the integer, and defaults to `"big"`. If *byteorder* is `"big"`, the most significant byte is at the beginning of the byte array. If *byteorder* is `"little"`, the most significant byte is at the end of the byte array. To request t...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
4ebb2a20-4542-583b-9929-2a927bae6e9e
docs
python
python_stdtypes
311
19
if signed and little_ordered and (little_ordered[-1] & 0x80): n -= 1 << 8*len(little_ordered) return n ``` New in version 3.2. Changed in version 3.11: Added default argument value for `byteorder`. int.as\_integer\_ratio()[¶](#int.as_integer_ratio "Link to this definition") :...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
9af3b468-a348-5141-be1a-8184b99f0843
docs
python
python_stdtypes
311
20
: Return a pair of integers whose ratio is exactly equal to the original float and with a positive denominator. Raises [`OverflowError`](exceptions.html#OverflowError "OverflowError") on infinities and a [`ValueError`](exceptions.html#ValueError "ValueError") on NaNs. float.is\_integer()[¶](#float.is_int...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
511ee88c-c8c5-5928-9068-465b2dbf22db
docs
python
python_stdtypes
311
21
: Return a representation of a floating-point number as a hexadecimal string. For finite floating-point numbers, this representation will always include a leading `0x` and a trailing `p` and exponent. *classmethod* float.fromhex(*s*)[¶](#float.fromhex "Link to this definition") : Class method to return...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
e80f4848-05ed-56b4-8b1b-112c529726af
docs
python
python_stdtypes
311
22
syntax specified in section 6.4.4.2 of the C99 standard, and also to the syntax used in Java 1.5 onwards. In particular, the output of [`float.hex()`](#float.hex "float.hex") is usable as a hexadecimal floating-point literal in C or Java code, and hexadecimal strings produced by C’s `%a` format character or Java’s `Dou...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
79bdde42-75de-5a22-9b45-59ded9b203ed
docs
python
python_stdtypes
311
23
### Hashing of numeric types[¶](#hashing-of-numeric-types "Link to this heading") For numbers `x` and `y`, possibly of different types, it’s a requirement that `hash(x) == hash(y)` whenever `x == y` (see the [`__hash__()`](../reference/datamodel.html#object.__hash__ "object.__hash__") method documentation for more det...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
b7322d8d-42ae-59fb-ad9a-8f2c4870912c
docs
python
python_stdtypes
311
24
[`float`](functions.html#float "float") and [`decimal.Decimal`](decimal.html#decimal.Decimal "decimal.Decimal"). Essentially, this function is given by reduction modulo `P` for a fixed prime `P`. The value of `P` is made available to Python as the [`modulus`](sys.html#sys.hash_info.modulus "sys.hash_info.modulus") attr...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
76d0fa00-c080-5809-9b1d-67efe5627b80
docs
python
python_stdtypes
311
25
* If `x = m / n` is a negative rational number define `hash(x)` as `-hash(-x)`. If the resulting hash is `-1`, replace it with `-2`. * The particular values `sys.hash_info.inf` and `-sys.hash_info.inf` are used as hash values for positive infinity or negative infinity (respectively). * For a [`complex`](functio...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
bd71e2c4-35cb-54a4-a6d9-960ecb809ecf
docs
python
python_stdtypes
311
26
Assumes m and n are integers, with n positive. Equivalent to hash(fractions.Fraction(m, n)). """ P = sys.hash_info.modulus # Remove common factors of P. (Unnecessary if m and n already coprime.) while m % P == n % P == 0: m, n = m // P, n // P if n % P == 0: hash_value = s...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
fe64ddd0-a982-519c-a492-1eebdb6f4de6
docs
python
python_stdtypes
311
27
hash_value = hash_float(z.real) + sys.hash_info.imag * hash_float(z.imag) # do a signed reduction modulo 2**sys.hash_info.width M = 2**(sys.hash_info.width - 1) hash_value = (hash_value & (M - 1)) - (hash_value & M) if hash_value == -1: hash_value = -2 return hash_value ``` ## Iterator ...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
1aba26dc-c7ae-5b86-b385-7061a316f1f0
docs
python
python_stdtypes
311
28
of iteration, additional methods can be provided to specifically request iterators for those iteration types. (An example of an object supporting multiple forms of iteration would be a tree structure which supports both breadth-first and depth-first traversal.) This method corresponds to the [`tp_it...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
67cdc5de-258a-53e4-bc36-c26a81c93040
docs
python
python_stdtypes
311
29
[`tp_iter`](../c-api/typeobj.html#c.PyTypeObject.tp_iter "PyTypeObject.tp_iter") slot of the type structure for Python objects in the Python/C API. iterator.\_\_next\_\_()[¶](#iterator.__next__ "Link to this definition") : Return the next item from the [iterator](../glossary.html#term-iterator). If there are...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
6498f86d-8c74-56cd-bb87-e39683fdc033
docs
python
python_stdtypes
311
30
[`StopIteration`](exceptions.html#StopIteration "StopIteration"), it must continue to do so on subsequent calls. Implementations that do not obey this property are deemed broken. ### Generator Types[¶](#generator-types "Link to this heading") Python’s [generator](../glossary.html#term-generator)s provide a convenient...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
45949b36-f792-57f2-98d1-74bc3f9e497e
docs
python
python_stdtypes
311
31
## Sequence Types — [`list`](#list "list"), [`tuple`](#tuple "tuple"), [`range`](#range "range")[¶](#sequence-types-list-tuple-range "Link to this heading") There are three basic sequence types: lists, tuples, and range objects. Additional sequence types tailored for processing of [binary data](#binaryseq) and [text s...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
201dc958-e7b0-58c5-b95b-cd440319ce98
docs
python
python_stdtypes
311
32
restrictions imposed by *s*. The `in` and `not in` operations have the same priorities as the comparison operations. The `+` (concatenation) and `*` (repetition) operations have the same priority as the corresponding numeric operations. [[3]](#id14) | Operation | Result | Notes | | --- | --- | --- | | `x in s` | `Tru...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
3903bfb2-3a64-52f9-9d7a-e324e7715d13
docs
python
python_stdtypes
311
33
| `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 corresponding elements. This means that to compare equal, every element must compare equal and the two sequences must be of th...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
2ec0a9d0-3ff9-53ad-88d5-26517e549273
docs
python
python_stdtypes
311
34
(such as [`str`](#str "str"), [`bytes`](#bytes "bytes") and [`bytearray`](#bytearray "bytearray")) also use them for subsequence testing: ```None >>> "gg" in "eggs" True ``` 2. Values of *n* less than `0` are treated as `0` (which yields an empty sequence of the same type as *s*). Note that items ...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
eecced03-7a8f-56f8-891f-d2b02602dc23
docs
python
python_stdtypes
311
35
[[3], [5], [7]] ``` Further explanation is available in the FAQ entry [How do I create a multidimensional list?](../faq/programming.html#faq-multidimensional-list). 3. If *i* or *j* is negative, the index is relative to the end of sequence *s*: `len(s) + i` or `len(s) + j` is substituted. But note that ...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
c95b5c7c-c35c-5485-a5b4-f8d0c5e1f73c
docs
python
python_stdtypes
311
36
When *k* is negative, *i* and *j* are reduced to `len(s) - 1` if they are greater. If *i* or *j* are omitted or `None`, they become “end” values (which end depends on the sign of *k*). Note, *k* cannot be zero. If *k* is `None`, it is treated like `1`. 6. Concatenating immutable sequences always results in ...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md
96640ea3-862b-584a-bba4-9558ca9530ed
docs
python
python_stdtypes
311
37
concatenation with a [`bytearray`](#bytearray "bytearray") object. [`bytearray`](#bytearray "bytearray") objects are mutable and have an efficient overallocation mechanism * if concatenating [`tuple`](#tuple "tuple") objects, extend a [`list`](#list "list") instead * for other types, investigate the rel...
large_dataset/raw/docs/python/stdtypes/stdtypes_311.md