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
65c6d4b3-b140-5fea-a808-217c82370c3d
docs
python
python_stdtypes
313
192
`dict.values()` to itself: ```None >>> d = {'a': 1} >>> d.values() == d.values() False ``` d | other : Create a new dictionary with the merged keys and values of *d* and *other*, which must both be dictionaries. The values of *other* take prior...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
91e79f0e-e8b2-5072-8877-8e0bfc221adf
docs
python
python_stdtypes
313
193
>>> list(reversed(d.items())) [('four', 4), ('three', 3), ('two', 2), ('one', 1)] ``` Changed in version 3.8: Dictionaries are now reversible. See also [`types.MappingProxyType`](types.html#types.MappingProxyType "types.MappingProxyType") can be used to create a read-only view of a [`dict`](#dict "di...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
455ea486-314b-5e46-83fb-364c20e825c1
docs
python
python_stdtypes
313
194
Keys and values are iterated over in insertion order. This allows the creation of `(value, key)` pairs 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 ...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
6e8ee2f1-14cd-5b39-b62e-f0086bf382d7
docs
python
python_stdtypes
313
195
: Return a [`types.MappingProxyType`](types.html#types.MappingProxyType "types.MappingProxyType") that wraps the original dictionary to which the view refers. Added in version 3.10. Keys views are set-like since their entries are unique and [hashable](../glossary.html#term-hashable). Items views also have s...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
a23a62f0-ca04-5990-9e69-26a7240444fd
docs
python
python_stdtypes
313
196
>>> dishes = {'eggs': 2, 'sausage': 1, 'bacon': 1, 'spam': 500} >>> keys = dishes.keys() >>> values = dishes.values() >>> # iteration >>> n = 0 >>> for val in values: ... n += val ... >>> print(n) 504 >>> # keys and values are iterated over in the same order (insertion order) >>> list(keys) ['eggs', 'sausage', 'b...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
6f4f13fd-7c12-5213-a83e-af50f24ae6b3
docs
python
python_stdtypes
313
197
## Context Manager Types[¶](#context-manager-types "Link to this heading") Python’s [`with`](../reference/compound_stmts.html#with) statement supports the concept of a runtime context defined by a context manager. This is implemented using a pair of methods that allow user-defined classes to define a runtime context t...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
9efd16fd-3869-506d-80c1-c2406fd5cbe3
docs
python
python_stdtypes
313
198
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.localcontext()`](decimal.html#decimal.localcontext "decimal.localcontext"). These managers set the active decimal...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
0f5b2022-1194-5404-88f1-c5565642e596
docs
python
python_stdtypes
313
199
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 to suppress the exception and continue execution with the statement immediately following the `with` statement. Ot...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
663bc715-83ca-566a-bcd2-80cdbaa6c01a
docs
python
python_stdtypes
313
200
context management code to easily detect whether or not an [`__exit__()`](../reference/datamodel.html#object.__exit__ "object.__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...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
f7648306-ddac-525f-8fa1-906948c400dc
docs
python
python_stdtypes
313
201
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_313.md
c0c02d2b-c101-5c5a-99fd-b8fc8a047513
docs
python
python_stdtypes
313
202
### Generic Alias Type[¶](#generic-alias-type "Link to this heading") `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") or [`d...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
89a6d696-ba5f-55e7-9f58-10ae5f8289af
docs
python
python_stdtypes
313
203
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_313.md
32320061-1f6e-539b-a294-44ba6b6c4c62
docs
python
python_stdtypes
313
204
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_313.md
1f0f5c29-4b84-5624-a4d0-8d3ecca076e1
docs
python
python_stdtypes
313
205
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_313.md
ea5f9176-91a3-54d3-a5df-466c7bd5f843
docs
python
python_stdtypes
313
206
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_313.md
a5d12201-f1c4-56f3-a339-1e2a963c5eaf
docs
python
python_stdtypes
313
207
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') >>> dict[str, Y][int] dict[str, int] ``` #### Standard Generic Classes[¶](#standard-gener...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
40217a00-8264-5054-a1b0-89a1663aaaae
docs
python
python_stdtypes
313
208
* [`collections.OrderedDict`](collections.html#collections.OrderedDict "collections.OrderedDict") * [`collections.Counter`](collections.html#collections.Counter "collections.Counter") * [`collections.ChainMap`](collections.html#collections.ChainMap "collections.ChainMap") * [`collections.abc.Awaitable`](collections.abc...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
82a6d8e1-8f55-54c1-b510-c41a9d40dfe5
docs
python
python_stdtypes
313
209
* [`collections.abc.Iterator`](collections.abc.html#collections.abc.Iterator "collections.abc.Iterator") * [`collections.abc.Generator`](collections.abc.html#collections.abc.Generator "collections.abc.Generator") * [`collections.abc.Reversible`](collections.abc.html#collections.abc.Reversible "collections.abc.Reversibl...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
0fd52c5e-48f7-52f7-8965-d94e85ebbac5
docs
python
python_stdtypes
313
210
* [`collections.abc.MutableMapping`](collections.abc.html#collections.abc.MutableMapping "collections.abc.MutableMapping") * [`collections.abc.Sequence`](collections.abc.html#collections.abc.Sequence "collections.abc.Sequence") * [`collections.abc.MutableSequence`](collections.abc.html#collections.abc.MutableSequence "...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
fc15d6ec-3b91-5ec8-a44e-e27d8a9005a7
docs
python
python_stdtypes
313
211
* [`contextlib.AbstractContextManager`](contextlib.html#contextlib.AbstractContextManager "contextlib.AbstractContextManager") * [`contextlib.AbstractAsyncContextManager`](contextlib.html#contextlib.AbstractAsyncContextManager "contextlib.AbstractAsyncContextManager") * [`dataclasses.Field`](dataclasses.html#dataclasse...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
1785da5e-b8c6-5398-8243-53477fae4890
docs
python
python_stdtypes
313
212
* [`shelve.DbfilenameShelf`](shelve.html#shelve.DbfilenameShelf "shelve.DbfilenameShelf") * [`shelve.Shelf`](shelve.html#shelve.Shelf "shelve.Shelf") * [`types.MappingProxyType`](types.html#types.MappingProxyType "types.MappingProxyType") * [`weakref.WeakKeyDictionary`](weakref.html#weakref.WeakKeyDictionary "weakref.W...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
0e58709e-6e1b-56b6-8e74-953260b0c931
docs
python
python_stdtypes
313
213
genericalias.\_\_args\_\_[¶](#genericalias.__args__ "Link to this definition") : 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 ...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
7ee5bddd-2b98-539e-824a-ba5e6ba9505e
docs
python
python_stdtypes
313
214
[`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 unpacked using the `*` operator (see [`TypeVarTuple`](typ...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
11b1380d-9e95-50c5-ba54-4cab5854d969
docs
python
python_stdtypes
313
215
[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. Added in version 3.9. ...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
f53b2698-1d38-502d-8555-c99765dfb3fe
docs
python
python_stdtypes
313
216
```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_313.md
cf266b7a-2a46-5fa9-b4f5-5d57fbf83081
docs
python
python_stdtypes
313
217
* 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_313.md
c7ce7fc2-f16b-5ca1-94c0-8049fadd78d4
docs
python
python_stdtypes
313
218
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_313.md
1ac0d6c6-759d-5221-9d4d-972374be3f76
docs
python
python_stdtypes
313
219
### 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_313.md
85898a8e-7271-552c-a144-c527b7610f84
docs
python
python_stdtypes
313
220
`m.__dict__ = {}`). Modifying [`__dict__`](../reference/datamodel.html#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'>`...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
12bb9a31-aebe-5860-8f59-522edd3607d5
docs
python
python_stdtypes
313
221
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()`](#...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
9ad07706-2b92-5c6e-92b8-628c5d7b91f8
docs
python
python_stdtypes
313
222
operates, and [`m.__func__`](../reference/datamodel.html#method.__func__ "method.__func__") is 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-def...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
ecb2ba98-95ff-5d22-a13e-1f604a0ef9a8
docs
python
python_stdtypes
313
223
Traceback (most recent call last): File "<stdin>", line 1, in <module> 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. #...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
b523a005-bafa-5963-a50b-6335bd56fefc
docs
python
python_stdtypes
313
224
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_313.md
24bb95fe-e168-547a-a335-1a5b3dfadf4d
docs
python
python_stdtypes
313
225
### 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_313.md
380cd9db-ef85-59ff-8b8f-9a3f671cfd30
docs
python
python_stdtypes
313
226
* As the body of a function instead of a [pass statement](../tutorial/controlflow.html#tut-pass). * In third-party libraries, such as [Numpy’s slicing and striding](https://numpy.org/doc/stable/user/basics.indexing.html#slicing-and-striding). Python also uses three dots in ways that are not `Ellipsis` objects, for ins...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
6416a669-7039-5ec0-813b-cff2890f2bb3
docs
python
python_stdtypes
313
227
information. There is exactly one [`NotImplemented`](constants.html#NotImplemented "NotImplemented") object. `type(NotImplemented)()` produces the singleton instance. It is written as `NotImplemented`. ### Internal Objects[¶](#internal-objects "Link to this heading") See [The standard type hierarchy](../reference/da...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
92a929a7-d953-5c5d-8690-43088af25065
docs
python
python_stdtypes
313
228
definition.\_\_qualname\_\_[¶](#definition.__qualname__ "Link to this definition") : The [qualified name](../glossary.html#term-qualified-name) of the class, function, method, descriptor, or generator instance. Added in version 3.3. definition.\_\_module\_\_[¶](#definition.__module__ "Link to this definitio...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
63b8e0a4-3b75-513b-8ffe-accf3cf8f9fc
docs
python
python_stdtypes
313
229
## Integer string conversion length limitation[¶](#integer-string-conversion-length-limitation "Link to this heading") 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 non-pow...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
8b2f2c14-fffc-5fda-9303-0aa2dd33f9e4
docs
python
python_stdtypes
313
230
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 counted towards the limit. When an operation would exceed the limit, a [`ValueError`](exceptions.html#ValueError "ValueError") is raised: ```N...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
203b039c-c995-527f-b9da-55d6862dcac7
docs
python
python_stdtypes
313
231
The default limit is 4300 digits as provided in [`sys.int_info.default_max_str_digits`](sys.html#sys.int_info "sys.int_info"). The lowest limit that can be configured is 640 digits as provided in [`sys.int_info.str_digits_check_threshold`](sys.html#sys.int_info "sys.int_info"). Verification: ```None >>> import sys >>...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
b51bd39d-6899-5e2d-98e9-d73715bd6482
docs
python
python_stdtypes
313
232
* `str(integer)`. * `repr(integer)`. * any other string conversion to base 10, for example `f"{integer}"`, `"{}".format(integer)`, or `b"%d" % integer`. The limitations do not apply to functions with a linear algorithm: * `int(string, base)` with base 2, 4, 8, 16, or 32. * [`int.from_bytes()`](#int.from_bytes "int....
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
6dc996e1-f4ad-5b96-b6a9-21c3db133d27
docs
python
python_stdtypes
313
233
* [`PYTHONINTMAXSTRDIGITS`](../using/cmdline.html#envvar-PYTHONINTMAXSTRDIGITS), e.g. `PYTHONINTMAXSTRDIGITS=640 python3` to set the limit to 640 or `PYTHONINTMAXSTRDIGITS=0 python3` to disable the limitation. * [`-X int_max_str_digits`](../using/cmdline.html#cmdoption-X), e.g. `python3 -X int_max_str_digits=640`...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
62ecf6b1-1dff-58d6-a013-a350ff1c31b9
docs
python
python_stdtypes
313
234
[`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_int_max_str_digits") and [`sys.set_int_max_str_digits()`](sys.html#sys.set_int_max_str_digits "sys.set_int_max_str_digits") are a getter and sette...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
982a59d4-a0d8-5d0e-853d-eeebb1471701
docs
python
python_stdtypes
313
235
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, usually at startup time or import time or even at installation time - anytime an up to date `.pyc` does not already exist for the code. A wor...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
ba896046-d998-594e-a36c-35dcad9aa074
docs
python
python_stdtypes
313
236
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 APIs were added in security patch releases in versions before 3.12. Example: ```None >>> import sys >>> if hasattr(sys, "set_int_max_str_digits"): ... upp...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
ed1ef7c5-754a-552a-8c6b-a75780bc1e7a
docs
python
python_stdtypes
313
237
They must have since the parser can’t tell the type of the operands. [4] ([1](#id6),[2](#id7),[3](#id8),[4](#id9)) Cased characters are those with general category property being one of “Lu” (Letter, uppercase), “Ll” (Letter, lowercase), or “Lt” (Letter, titlecase). [5] ([1](#id10),[2](#id11)) To format only a tu...
large_dataset/raw/docs/python/stdtypes/stdtypes_313.md
f0f12a78-92a0-5f77-8ce5-855549c4874e
docs
python
python_stdtypes
314
0
# Built-in Types¶ Source: https://docs.python.org/3.14/library/stdtypes.html Version: 3.14 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_314.md
069f05e2-699f-55d3-a067-8cf1c411c5c2
docs
python
python_stdtypes
314
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_314.md
dce8cff3-d087-5ad5-acd7-88e7c052a08f
docs
python
python_stdtypes
314
2
* empty sequences and collections: `''`, `()`, `[]`, `{}`, `set()`, `range(0)` Operations and built-in functions that have a Boolean result always return `0` 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 thei...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
20f27ce0-3e68-502c-af4b-942f7979ee28
docs
python
python_stdtypes
314
3
3. `not` has a lower priority than non-Boolean operators, so `not a == b` is interpreted as `not (a == b)`, and `a == not b` is a syntax error. ## 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 B...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
bee933e4-c277-5aa3-978f-7cb4ae002f6b
docs
python
python_stdtypes
314
4
The `==` operator is always defined but for some object types (for example, class objects) is equivalent to [`is`](../reference/expressions.html#is). The `<`, `<=`, `>` and `>=` operators are only defined where they make sense; for example, they raise a [`TypeError`](exceptions.html#TypeError "TypeError") exception whe...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
bbdd4e0f-cb74-54d9-9f59-74326ec2dd22
docs
python
python_stdtypes
314
5
[`__ge__()`](../reference/datamodel.html#object.__ge__ "object.__ge__") (in general, [`__lt__()`](../reference/datamodel.html#object.__lt__ "object.__lt__") and [`__eq__()`](../reference/datamodel.html#object.__eq__ "object.__eq__") are sufficient, if you want the conventional meanings of the comparison operators). Th...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
0926ec28-b271-5f96-a31f-919f52032d7a
docs
python
python_stdtypes
314
6
## Numeric Types — [`int`](functions.html#int "int"), [`float`](functions.html#float "float"), [`complex`](functions.html#complex "complex")[¶](#numeric-types-int-float-complex "Link to this heading") There are three distinct numeric types: *integers*, *floating-point numbers*, and *complex numbers*. In addition, Bool...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
a02cbefc-2d08-5500-9163-1aea8ed3cc35
docs
python
python_stdtypes
314
7
rationals, and [`decimal.Decimal`](decimal.html#decimal.Decimal "decimal.Decimal"), for floating-point numbers with user-definable precision.) Numbers are created by numeric literals or as the result of built-in functions and operators. Unadorned integer literals (including hex, octal and binary numbers) yield integer...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
8fc01820-9a4b-5c9b-810e-639c870d1938
docs
python
python_stdtypes
314
8
widened to that of the other, where integer is narrower than floating point. Arithmetic with complex and real operands is defined by the usual mathematical formula, for example: ```None x + complex(u, v) = complex(x + u, v) x * complex(u, v) = complex(x * u, x * v) ``` A comparison between numbers of different types ...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
e9cbaf2c-fdf4-5ab1-b0bf-255e69aa4cc3
docs
python
python_stdtypes
314
9
| `abs(x)` | absolute value or magnitude of *x* | | [`abs()`](functions.html#abs "abs") | | `int(x)` | *x* converted to integer | (3)(6) | [`int()`](functions.html#int "int") | | `float(x)` | *x* converted to floating point | (4)(6) | [`float()`](functions.html#float "float") | | `complex(re, im)` | a complex number w...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
fca0c3c3-df77-5ddd-aca2-474f653c93d6
docs
python
python_stdtypes
314
10
the result has type [`float`](functions.html#float "float"). In general, the result is a whole integer, though the result’s type is not necessarily [`int`](functions.html#int "int"). The result is always rounded towards minus infinity: `1//2` is `0`, `(-1)//2` is `-1`, `1//(-2)` is `-1`, and `(-1)//(-2)` is...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
a7d3fd9d-9e92-570a-ad89-ac5f1830ef70
docs
python
python_stdtypes
314
11
6. The numeric literals accepted include the digits `0` to `9` or any Unicode equivalent (code points with the `Nd` property). See [the Unicode Standard](https://unicode.org/Public/UNIDATA/extracted/DerivedNumericType.txt) for a complete list of code points with the `Nd` property. All [`numbers.Real`](number...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
6aca36d0-ec68-5de5-ad26-5ec12dca1cb8
docs
python
python_stdtypes
314
12
| [`math.ceil(x)`](math.html#math.ceil "math.ceil") | the least [`Integral`](numbers.html#numbers.Integral "numbers.Integral") >= *x* | For additional numeric operations see the [`math`](math.html#module-math "math: Mathematical functions (sin() etc.).") and [`cmath`](cmath.html#module-cmath "cmath: Mathematical funct...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
5513060f-3f6f-5439-8eec-daf29b0acfef
docs
python
python_stdtypes
314
13
| `x | y` | bitwise *or* of *x* and *y* | (4) | | `x ^ y` | bitwise *exclusive or* of *x* and *y* | (4) | | `x & y` | bitwise *and* of *x* and *y* | (4) | | `x << n` | *x* shifted left by *n* bits | (1)(2) | | `x >> n` | *x* shifted right by *n* bits | (1)(3) | | `~x` | the bits of *x* inverted | | Notes: 1. Negativ...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
cf1a1a26-e520-57af-8c7c-525d1bfe8527
docs
python
python_stdtypes
314
14
### Additional Methods on Integer Types[¶](#additional-methods-on-integer-types "Link to this heading") The int type implements the [`numbers.Integral`](numbers.html#numbers.Integral "numbers.Integral") [abstract base class](../glossary.html#term-abstract-base-class). In addition, it provides a few more methods: int....
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
6b6ff45e-0a63-55b2-8542-c1b0b8b77515
docs
python
python_stdtypes
314
15
s = bin(self) # binary representation: bin(-37) --> '-0b100101' s = s.lstrip('-0b') # remove leading zeros and minus sign return len(s) # len('100101') --> 6 ``` Added in version 3.1. int.bit\_count()[¶](#int.bit_count "Link to this definition") : Return the number of on...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
39499953-8787-5fa1-a231-5152eb12e164
docs
python
python_stdtypes
314
16
b'\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00' >>> (-1024).to_bytes(10, byteorder='big', signed=True) b'\xff\xff\xff\xff\xff\xff\xff\xff\xfc\x00' >>> x = 1000 >>> x.to_bytes((x.bit_length() + 7) // 8, byteorder='little') b'\xe8\x03' ``` The integer is represented using *length* bytes, and ...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
c1908078-f065-5d8c-b468-2c83eebfbf68
docs
python
python_stdtypes
314
17
given, an [`OverflowError`](exceptions.html#OverflowError "OverflowError") is raised. The default value for *signed* is `False`. The default values can be used to conveniently turn an integer into a single byte object: ```None >>> (65).to_bytes() b'A' ``` However, when using the d...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
d7505078-e42b-5bfc-badd-469a34078460
docs
python
python_stdtypes
314
18
*classmethod* int.from\_bytes(*bytes*, *byteorder='big'*, *\**, *signed=False*)[¶](#int.from_bytes "Link to this definition") : Return the integer represented by the given array of bytes. ```None >>> int.from_bytes(b'\x00\x10', byteorder='big') 16 >>> int.from_bytes(b'\x00\x10', byteorder='little') ...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
277f4170-32f9-5868-9c74-dfb9fafc2865
docs
python
python_stdtypes
314
19
the end of the byte array. To request the native byte order of the host system, use [`sys.byteorder`](sys.html#sys.byteorder "sys.byteorder") as the byte order value. The *signed* argument indicates whether two’s complement is used to represent the integer. Equivalent to: ```None def from...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
4e40d234-25ef-53ff-9d06-74195f12a092
docs
python
python_stdtypes
314
20
: Return a pair of integers whose ratio is equal to the original integer and has a positive denominator. The integer ratio of integers (whole numbers) is always the integer as the numerator and `1` as the denominator. Added in version 3.8. int.is\_integer()[¶](#int.is_integer "Link to this definitio...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
b6e4efc9-4cd6-531c-b831-580aca5d0293
docs
python
python_stdtypes
314
21
floating-point number with the same value (within Python’s floating-point precision) is returned. If the argument is outside the range of a Python float, an [`OverflowError`](exceptions.html#OverflowError "OverflowError") will be raised. For a general Python object `x`, `float.from_number(x)` delegates...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
2a0e5747-9fd2-5f96-ab34-e3842058d9e5
docs
python
python_stdtypes
314
22
float.is\_integer()[¶](#float.is_integer "Link to this definition") : Return `True` if the float instance is finite with integral value, and `False` otherwise: ```None >>> (-2.0).is_integer() True >>> (3.2).is_integer() False ``` Two methods support conversion to and from hexadecimal str...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
239cc0b4-b1c1-593b-9eb4-1d34fc14b38c
docs
python
python_stdtypes
314
23
: Class method to return the float represented by a hexadecimal string *s*. The string *s* may have leading and trailing whitespace. Note that [`float.hex()`](#float.hex "float.hex") is an instance method, while [`float.fromhex()`](#float.fromhex "float.fromhex") is a class method. A hexadecimal string take...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
d299d849-c422-5e78-8005-fc4bdd03de99
docs
python
python_stdtypes
314
24
character or Java’s `Double.toHexString` are accepted by [`float.fromhex()`](#float.fromhex "float.fromhex"). Note that the exponent is written in decimal rather than hexadecimal, and that it gives the power of 2 by which to multiply the coefficient. For example, the hexadecimal string `0x3.a7p10` represents the float...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
ffc5363c-0214-51e5-b3ac-7a8ded12d29a
docs
python
python_stdtypes
314
25
: Class method to convert a number to a complex number. For a general Python object `x`, `complex.from_number(x)` delegates to `x.__complex__()`. If [`__complex__()`](../reference/datamodel.html#object.__complex__ "object.__complex__") is not defined then it falls back to [`__float__()`](../reference/dat...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
82ae1a0a-615e-53f5-88de-ae5df53caa3a
docs
python
python_stdtypes
314
26
[`float`](functions.html#float "float"), [`decimal.Decimal`](decimal.html#decimal.Decimal "decimal.Decimal") and [`fractions.Fraction`](fractions.html#fractions.Fraction "fractions.Fraction")) Python’s hash for numeric types is based on a single mathematical function that’s defined for any rational number, and hence ap...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
afc0e487-a0ca-5ab2-9080-dd97edcf1e31
docs
python
python_stdtypes
314
27
longs and `P = 2**61 - 1` on machines with 64-bit C longs. Here are the rules in detail: * If `x = m / n` is a nonnegative rational number and `n` is not divisible by `P`, define `hash(x)` as `m * invmod(n, P) % P`, where `invmod(n, P)` gives the inverse of `n` modulo `P`. * If `x = m / n` is a nonnegative ration...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
3d0c9ed0-bf9c-54b3-b562-b6077698840e
docs
python
python_stdtypes
314
28
sys.hash_info.imag * hash(z.imag)`, reduced modulo `2**sys.hash_info.width` so that it lies in `range(-2**(sys.hash_info.width - 1), 2**(sys.hash_info.width - 1))`. Again, if the result is `-1`, it’s replaced with `-2`. To clarify the above rules, here’s some example Python code, equivalent to the built-in has...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
77a7220b-8f3d-5afa-9629-b31684037c2e
docs
python
python_stdtypes
314
29
# pow(n, P-2, P) gives the inverse of n modulo P. hash_value = (abs(m) % P) * pow(n, P - 2, P) % P if m < 0: hash_value = -hash_value if hash_value == -1: hash_value = -2 return hash_value def hash_float(x): """Compute the hash of a float x.""" if math.isnan(x): ...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
b113d987-68db-5419-bc31-483f22811415
docs
python
python_stdtypes
314
30
## Boolean Type - [`bool`](functions.html#bool "bool")[¶](#boolean-type-bool "Link to this heading") Booleans represent truth values. The [`bool`](functions.html#bool "bool") type has exactly two constant instances: `True` and `False`. The built-in function [`bool()`](functions.html#bool "bool") converts any value to...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
c0e4925c-5eb1-56e1-9fe0-b1840a172dba
docs
python
python_stdtypes
314
31
[`bool`](functions.html#bool "bool") is a subclass of [`int`](functions.html#int "int") (see [Numeric Types — int, float, complex](#typesnumeric)). In many numeric contexts, `False` and `True` behave like the integers 0 and 1, respectively. However, relying on this is discouraged; explicitly convert using [`int()`](fun...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
f532319d-ee7e-53f8-a7e5-afb97dd36fe5
docs
python
python_stdtypes
314
32
iterator protocol described below. If a container supports different types 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 bread...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
c7532468-d2e6-5c7e-a3a8-91f021f37c64
docs
python
python_stdtypes
314
33
[`in`](../reference/expressions.html#in) statements. This method corresponds to the [`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") : ...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
dd117eea-e06b-551f-9902-97d2aef76088
docs
python
python_stdtypes
314
34
Once an iterator’s [`__next__()`](#iterator.__next__ "iterator.__next__") method raises [`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 thi...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
176b85a6-72bc-599e-bc41-4bfd594e60b4
docs
python
python_stdtypes
314
35
## 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_314.md
65499bec-b168-5b6d-9833-b549e39de750
docs
python
python_stdtypes
314
36
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_314.md
56a14e98-f447-5836-8a39-a375ce84efe2
docs
python
python_stdtypes
314
37
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 the same type and have the same length. (For full details see [Comparisons](../reference/expressions.html#comparisons) in the language referen...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
e00a8df7-1609-5e2a-bf07-fded718ee11f
docs
python
python_stdtypes
314
38
```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 in the sequence *s* are not copied; they are referenced multiple times. This often haunts new Python programmers; consider: ```None ...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
ddbbf2ec-9256-5edb-8770-8bd4e73558d9
docs
python
python_stdtypes
314
39
[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 `-0` is still `0`. 4. The slice of *s* from *i* to *j* is defined as the sequ...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
91149f7d-fd7f-5cf9-bf75-4d130eb8772a
docs
python
python_stdtypes
314
40
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_314.md
b0dec684-7580-5503-b492-3b78964e65be
docs
python
python_stdtypes
314
41
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_314.md
32515384-5d5f-52a5-aa0c-de4b6a83d362
docs
python
python_stdtypes
314
42
Raises [`ValueError`](exceptions.html#ValueError "ValueError") if *value* is not found in *sequence*. The *start* or *stop* arguments allow for efficient searching of subsections of the sequence, beginning at *start* and ending at *stop*. This is roughly equivalent to `start + sequence[start:stop].inde...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
d8e0dbbb-4e58-5095-9341-4de472514b34
docs
python
python_stdtypes
314
43
Attempting to hash an immutable sequence that contains unhashable values will result in [`TypeError`](exceptions.html#TypeError "TypeError"). ### Mutable Sequence Types[¶](#mutable-sequence-types "Link to this heading") The operations in the following table are defined on mutable sequence types. The [`collections.abc...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
aa084012-04e5-53ca-9298-32bf44c538d4
docs
python
python_stdtypes
314
44
| `s[i:j] = t` | slice of *s* from *i* to *j* is replaced by the contents of the iterable *t* | | | `del s[i:j]` | removes the elements of `s[i:j]` from the list (same as `s[i:j] = []`) | | | `s[i:j:k] = t` | the elements of `s[i:j:k]` are replaced by those of *t* | (1) | | `del s[i:j:k]` | removes the elements of `s...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
6ee0e7fa-3f83-56f1-934b-35e1c88cbd9b
docs
python
python_stdtypes
314
45
Mutable sequence types also support the following methods: sequence.append(*value*, */*)[¶](#sequence.append "Link to this definition") : Append *value* to the end of the sequence This is equivalent to writing `seq[len(seq):len(seq)] = [value]`. sequence.clear()[¶](#sequence.clear "Link to this definition") : ...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
15f4e611-2ecd-5b9d-bcb0-c980485455da
docs
python
python_stdtypes
314
46
For the most part, this is the same as writing `seq[len(seq):len(seq)] = iterable`. sequence.insert(*index*, *value*, */*)[¶](#sequence.insert "Link to this definition") : Insert *value* into *sequence* at the given *index*. This is equivalent to writing `sequence[index:index] = [value]`. sequence.pop(*...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
1bb628cc-762e-5f9f-b2fa-f1aa596912b8
docs
python
python_stdtypes
314
47
To remind users that it operates by side-effect, it returns `None`. ### Lists[¶](#lists "Link to this heading") Lists are mutable sequences, typically used to store collections of homogeneous items (where the precise degree of similarity will vary by application). *class* list(*iterable=()*, */*)[¶](#list "Link ...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
4d50fea1-9b95-5c13-9c69-c961337a44df
docs
python
python_stdtypes
314
48
`list( (1, 2, 3) )` returns `[1, 2, 3]`. If no argument is given, the constructor creates a new empty list, `[]`. Many other operations also produce lists, including the [`sorted()`](functions.html#sorted "sorted") built-in. Lists implement all of the [common](#typesseq-common) and [mutable](#...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
1ea20a9b-af5d-548b-8c95-9b34b1e72b58
docs
python
python_stdtypes
314
49
*key* specifies a function of one argument that is used to extract a comparison key from each list element (for example, `key=str.lower`). The key corresponding to each item in the list is calculated once and then used for the entire sorting process. The default value of `None` m...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
4e8d1bf6-7717-53fd-aac1-9aaa296cf1d9
docs
python
python_stdtypes
314
50
explicitly request a new sorted list instance). The [`sort()`](#list.sort "list.sort") method is guaranteed to be stable. A sort is stable if it guarantees not to change the relative order of elements that compare equal — this is helpful for sorting in multiple passes (for example, sort...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
b8adff62-ef21-5a18-bfb5-c53cbf9cdbc5
docs
python
python_stdtypes
314
51
lst[i] # list.__getitem__ ``` The following methods traverse the list and use [atomic](../glossary.html#term-atomic-operation) reads of each item to perform their function. That means that they may return results affected by concurrent modifications: ```None item in lst lst.index(item) lst.count(item) ``` All of t...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
a6ef0f4f-2436-5494-8ecd-ef4cf59afa9e
docs
python
python_stdtypes
314
52
Methods that only operate on a single elements with no shifting required are [atomic](../glossary.html#term-atomic-operation): ```None lst.append(x) # append to the end of the list, no shifting required lst.pop() # pop element from the end of the list, no shifting required ``` The [`clear()`](#list.clear "list....
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md
69d575c5-0e90-508d-99c1-f75a602ea439
docs
python
python_stdtypes
314
53
The [`remove()`](#list.remove "list.remove") method may allow concurrent modifications since element comparison may execute arbitrary Python code (via [`__eq__()`](../reference/datamodel.html#object.__eq__ "object.__eq__")). [`extend()`](#list.extend "list.extend") is safe to call from multiple threads. However, its g...
large_dataset/raw/docs/python/stdtypes/stdtypes_314.md