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
a614648c-b850-51a8-819e-35f548588c1d
docs
python
python_stdlib2
315
13
a list that stores only homogeneous data and stores it more compactly. The following example shows an array of numbers stored as two byte unsigned binary numbers (typecode `"H"`) rather than the usual 16 bytes per entry for regular lists of Python int objects: ```None >>> from array import array >>> a = array('H', [40...
large_dataset/raw/docs/python/stdlib2/stdlib2_315.md
4660d4e5-accc-5066-b953-22267833ab4d
docs
python
python_stdlib2
315
14
def breadth_first_search(unsearched): node = unsearched.popleft() for m in gen_moves(node): if is_goal(m): return m unsearched.append(m) ``` In addition to alternative list implementations, the library also offers other tools such as the [`bisect`](../library/bisect.html#module-bise...
large_dataset/raw/docs/python/stdlib2/stdlib2_315.md
772f37d7-28a5-5680-ab7d-bbb019c3967b
docs
python
python_stdlib2
315
15
```None >>> from heapq import heapify, heappop, heappush >>> data = [1, 3, 5, 7, 9, 2, 4, 6, 8, 0] >>> heapify(data) # rearrange the list into heap order >>> heappush(data, -5) # add a new entry >>> [heappop(data) for i in range(3)] # fetch the three smallest entries [-5, 0, 1] ```...
large_dataset/raw/docs/python/stdlib2/stdlib2_315.md
57365bd2-a720-53e9-b8e1-461375198fde
docs
python
python_stdlib2
315
16
* control over rounding to meet legal or regulatory requirements, * tracking of significant decimal places, or * applications where the user expects the results to match calculations done by hand. For example, calculating a 5% tax on a 70 cent phone charge gives different results in decimal floating point and binary...
large_dataset/raw/docs/python/stdlib2/stdlib2_315.md
4ac29e4b-f3a8-5272-8a70-2b65f182bee6
docs
python
python_stdlib2
315
17
Exact representation enables the [`Decimal`](../library/decimal.html#decimal.Decimal "decimal.Decimal") class to perform modulo calculations and equality tests that are unsuitable for binary floating point: ```None >>> Decimal('1.00') % Decimal('.10') Decimal('0.00') >>> 1.00 % 0.10 0.09999999999999995 >>> sum([Decim...
large_dataset/raw/docs/python/stdlib2/stdlib2_315.md
e2f9ba48-30c1-59b5-83a4-2df55ca23fd2
docs
python
python_stdlib2
38
0
# 11.Brief Tour of the Standard Library — Part II¶ Source: https://docs.python.org/3.8/tutorial/stdlib2.html Version: 3.8 This second tour covers more advanced modules that support professional programming needs. These modules rarely occur in small scripts. ## 11.1. Output Formatting[¶](#output-formatting "Permalink...
large_dataset/raw/docs/python/stdlib2/stdlib2_38.md
3e1b0892-d68b-5955-9273-34aa5f30eed9
docs
python
python_stdlib2
38
1
When the result is longer than one line, the “pretty printer” adds line breaks and indentation to more clearly reveal data structure: ```None >>> import pprint >>> t = [[[['black', 'cyan'], 'white', ['green', 'red']], [['magenta', ... 'yellow'], 'blue']]] ... >>> pprint.pprint(t, width=30) [[[['black', 'cyan'], ...
large_dataset/raw/docs/python/stdlib2/stdlib2_38.md
ca7b56f4-c740-5f6c-b807-5435c6e2ad41
docs
python
python_stdlib2
38
2
The [`locale`](../library/locale.html#module-locale "locale: Internationalization services.") module accesses a database of culture specific data formats. The grouping attribute of locale’s format function provides a direct way of formatting numbers with group separators: ```None >>> import locale >>> locale.setlocale...
large_dataset/raw/docs/python/stdlib2/stdlib2_38.md
5ec6b909-a2bd-5745-96d8-4bbf03fddee6
docs
python
python_stdlib2
38
3
to customize their applications without having to alter the application. The format uses placeholder names formed by `$` with valid Python identifiers (alphanumeric characters and underscores). Surrounding the placeholder with braces allows it to be followed by more alphanumeric letters with no intervening spaces. Wri...
large_dataset/raw/docs/python/stdlib2/stdlib2_38.md
02227a5e-043d-5748-93aa-60aaf68c78a1
docs
python
python_stdlib2
38
4
[`safe_substitute()`](../library/string.html#string.Template.safe_substitute "string.Template.safe_substitute") method may be more appropriate — it will leave placeholders unchanged if data is missing: ```None >>> t = Template('Return the $item to $owner.') >>> d = dict(item='unladen swallow') >>> t.substitute(d) Trac...
large_dataset/raw/docs/python/stdlib2/stdlib2_38.md
bb98f8ab-5089-5430-82cd-ebf2c8fe1494
docs
python
python_stdlib2
38
5
>>> for i, filename in enumerate(photofiles): ... base, ext = os.path.splitext(filename) ... newname = t.substitute(d=date, n=i, f=ext) ... print('{0} --> {1}'.format(filename, newname)) img_1074.jpg --> Ashley_0.jpg img_1076.jpg --> Ashley_1.jpg img_1077.jpg --> Ashley_2.jpg ``` Another application for t...
large_dataset/raw/docs/python/stdlib2/stdlib2_38.md
3c5b6e24-c70b-53b5-99a4-c4e66176f03b
docs
python
python_stdlib2
38
6
how to loop through header information in a ZIP file without using the [`zipfile`](../library/zipfile.html#module-zipfile "zipfile: Read and write ZIP-format archive files.") module. Pack codes `"H"` and `"I"` represent two and four byte unsigned numbers respectively. The `"<"` indicates that they are standard size and...
large_dataset/raw/docs/python/stdlib2/stdlib2_38.md
beb95352-338a-55f7-972d-39b5230c01fb
docs
python
python_stdlib2
38
7
## 11.4. Multi-threading[¶](#multi-threading "Permalink to this headline") Threading is a technique for decoupling tasks which are not sequentially dependent. Threads can be used to improve the responsiveness of applications that accept user input while other tasks run in the background. A related use case is running ...
large_dataset/raw/docs/python/stdlib2/stdlib2_38.md
573048bb-f14d-5f3b-b03c-fc5bbc1fa885
docs
python
python_stdlib2
38
8
background = AsyncZip('mydata.txt', 'myarchive.zip') background.start() print('The main program continues to run in foreground.') background.join() # Wait for the background task to finish print('Main program waited until background was done.') ``` The principal challenge of multi-threaded applications is coordina...
large_dataset/raw/docs/python/stdlib2/stdlib2_38.md
1b3e87ad-b3e9-513d-977e-2e5708204a3f
docs
python
python_stdlib2
38
9
coordination are easier to design, more readable, and more reliable. ## 11.5. Logging[¶](#logging "Permalink to this headline") The [`logging`](../library/logging.html#module-logging "logging: Flexible event logging system for applications.") module offers a full featured and flexible logging system. At its simplest,...
large_dataset/raw/docs/python/stdlib2/stdlib2_38.md
719b06ca-2dbb-5c15-9809-1666ab1085b0
docs
python
python_stdlib2
38
10
through email, datagrams, sockets, or to an HTTP Server. New filters can select different routing based on message priority: `DEBUG`, `INFO`, `WARNING`, `ERROR`, and `CRITICAL`. The logging system can be configured directly from Python or can be loaded from a user editable configuration file for customized logging wit...
large_dataset/raw/docs/python/stdlib2/stdlib2_38.md
a7d12a93-3f74-59c2-990f-1d050678e070
docs
python
python_stdlib2
38
11
The [`weakref`](../library/weakref.html#module-weakref "weakref: Support for weak references and weak dictionaries.") module provides tools for tracking objects without creating a reference. When the object is no longer needed, it is automatically removed from a weakref table and a callback is triggered for weakref obj...
large_dataset/raw/docs/python/stdlib2/stdlib2_38.md
ef30bf19-9f08-5680-bd4f-c85c42a223ff
docs
python
python_stdlib2
38
12
Traceback (most recent call last): File "<stdin>", line 1, in <module> d['primary'] # entry was automatically removed File "C:/python38/lib/weakref.py", line 46, in __getitem__ o = self.data[key]() KeyError: 'primary' ``` ## 11.7. Tools for Working with Lists[¶](#tools-for-working-with-lists...
large_dataset/raw/docs/python/stdlib2/stdlib2_38.md
4715607d-8442-5399-88d4-d71bba595491
docs
python
python_stdlib2
38
13
>>> from array import array >>> a = array('H', [4000, 10, 700, 22222]) >>> sum(a) 26932 >>> a[1:3] array('H', [10, 700]) ``` The [`collections`](../library/collections.html#module-collections "collections: Container datatypes") module provides a [`deque()`](../library/collections.html#collections.deque "collections.de...
large_dataset/raw/docs/python/stdlib2/stdlib2_38.md
3e8a821a-a0b2-55d2-a376-be88b3844f0b
docs
python
python_stdlib2
38
14
tools such as the [`bisect`](../library/bisect.html#module-bisect "bisect: Array bisection algorithms for binary searching.") module with functions for manipulating sorted lists: ```None >>> import bisect >>> scores = [(100, 'perl'), (200, 'tcl'), (400, 'lua'), (500, 'python')] >>> bisect.insort(scores, (300, 'ruby'))...
large_dataset/raw/docs/python/stdlib2/stdlib2_38.md
ebe38a81-f5fe-5ab9-84c9-a9eb40156528
docs
python
python_stdlib2
38
15
>>> [heappop(data) for i in range(3)] # fetch the three smallest entries [-5, 0, 1] ``` ## 11.8. Decimal Floating Point Arithmetic[¶](#decimal-floating-point-arithmetic "Permalink to this headline") The [`decimal`](../library/decimal.html#module-decimal "decimal: Implementation of the General Decimal Arithmetic Spe...
large_dataset/raw/docs/python/stdlib2/stdlib2_38.md
7ab013d1-dcaa-54a2-a712-01f069c1b508
docs
python
python_stdlib2
38
16
results in decimal floating point and binary floating point. The difference becomes significant if the results are rounded to the nearest cent: ```None >>> from decimal import * >>> round(Decimal('0.70') * Decimal('1.05'), 2) Decimal('0.74') >>> round(.70 * 1.05, 2) 0.73 ``` The [`Decimal`](../library/decimal.html#de...
large_dataset/raw/docs/python/stdlib2/stdlib2_38.md
c5447111-1b65-5a35-acd2-e26d393d6b10
docs
python
python_stdlib2
38
17
The [`decimal`](../library/decimal.html#module-decimal "decimal: Implementation of the General Decimal Arithmetic Specification.") module provides arithmetic with as much precision as needed: ```None >>> getcontext().prec = 36 >>> Decimal(1) / Decimal(7) Decimal('0.142857142857142857142857142857142857') ```
large_dataset/raw/docs/python/stdlib2/stdlib2_38.md
d8b30779-9df1-513d-aafe-a51b20d51258
docs
python
python_stdlib2
39
0
# 11.Brief Tour of the Standard Library — Part II¶ Source: https://docs.python.org/3.9/tutorial/stdlib2.html Version: 3.9 This second tour covers more advanced modules that support professional programming needs. These modules rarely occur in small scripts. ## 11.1. Output Formatting[¶](#output-formatting "Permalink...
large_dataset/raw/docs/python/stdlib2/stdlib2_39.md
bb436b66-fb5f-5c2c-9621-bcf89bdfe007
docs
python
python_stdlib2
39
1
When the result is longer than one line, the “pretty printer” adds line breaks and indentation to more clearly reveal data structure: ```None >>> import pprint >>> t = [[[['black', 'cyan'], 'white', ['green', 'red']], [['magenta', ... 'yellow'], 'blue']]] ... >>> pprint.pprint(t, width=30) [[[['black', 'cyan'], ...
large_dataset/raw/docs/python/stdlib2/stdlib2_39.md
88f281e8-6892-50a2-88fc-0d4bdaf65e82
docs
python
python_stdlib2
39
2
The [`locale`](../library/locale.html#module-locale "locale: Internationalization services.") module accesses a database of culture specific data formats. The grouping attribute of locale’s format function provides a direct way of formatting numbers with group separators: ```None >>> import locale >>> locale.setlocale...
large_dataset/raw/docs/python/stdlib2/stdlib2_39.md
d121ad23-974f-5520-9236-e967d116d181
docs
python
python_stdlib2
39
3
to customize their applications without having to alter the application. The format uses placeholder names formed by `$` with valid Python identifiers (alphanumeric characters and underscores). Surrounding the placeholder with braces allows it to be followed by more alphanumeric letters with no intervening spaces. Wri...
large_dataset/raw/docs/python/stdlib2/stdlib2_39.md
1d4aa549-299f-5cfc-a267-9e8b44425588
docs
python
python_stdlib2
39
4
[`safe_substitute()`](../library/string.html#string.Template.safe_substitute "string.Template.safe_substitute") method may be more appropriate — it will leave placeholders unchanged if data is missing: ```None >>> t = Template('Return the $item to $owner.') >>> d = dict(item='unladen swallow') >>> t.substitute(d) Trac...
large_dataset/raw/docs/python/stdlib2/stdlib2_39.md
68ac331d-f42b-58bd-9c7a-740b9eba4bcf
docs
python
python_stdlib2
39
5
>>> for i, filename in enumerate(photofiles): ... base, ext = os.path.splitext(filename) ... newname = t.substitute(d=date, n=i, f=ext) ... print('{0} --> {1}'.format(filename, newname)) img_1074.jpg --> Ashley_0.jpg img_1076.jpg --> Ashley_1.jpg img_1077.jpg --> Ashley_2.jpg ``` Another application for t...
large_dataset/raw/docs/python/stdlib2/stdlib2_39.md
6431aee2-bdeb-537c-a6de-74bac7d427b2
docs
python
python_stdlib2
39
6
how to loop through header information in a ZIP file without using the [`zipfile`](../library/zipfile.html#module-zipfile "zipfile: Read and write ZIP-format archive files.") module. Pack codes `"H"` and `"I"` represent two and four byte unsigned numbers respectively. The `"<"` indicates that they are standard size and...
large_dataset/raw/docs/python/stdlib2/stdlib2_39.md
3cd10a77-31a6-5202-834a-1800d445e8f5
docs
python
python_stdlib2
39
7
## 11.4. Multi-threading[¶](#multi-threading "Permalink to this headline") Threading is a technique for decoupling tasks which are not sequentially dependent. Threads can be used to improve the responsiveness of applications that accept user input while other tasks run in the background. A related use case is running ...
large_dataset/raw/docs/python/stdlib2/stdlib2_39.md
8642053f-d72e-5c15-a83b-da0bb109beba
docs
python
python_stdlib2
39
8
background = AsyncZip('mydata.txt', 'myarchive.zip') background.start() print('The main program continues to run in foreground.') background.join() # Wait for the background task to finish print('Main program waited until background was done.') ``` The principal challenge of multi-threaded applications is coordina...
large_dataset/raw/docs/python/stdlib2/stdlib2_39.md
3708566a-7d9b-51c6-913f-fd9e063b35bb
docs
python
python_stdlib2
39
9
coordination are easier to design, more readable, and more reliable. ## 11.5. Logging[¶](#logging "Permalink to this headline") The [`logging`](../library/logging.html#module-logging "logging: Flexible event logging system for applications.") module offers a full featured and flexible logging system. At its simplest,...
large_dataset/raw/docs/python/stdlib2/stdlib2_39.md
af672620-6320-5e5f-b9a8-5e676df99208
docs
python
python_stdlib2
39
10
through email, datagrams, sockets, or to an HTTP Server. New filters can select different routing based on message priority: `DEBUG`, `INFO`, `WARNING`, `ERROR`, and `CRITICAL`. The logging system can be configured directly from Python or can be loaded from a user editable configuration file for customized logging wit...
large_dataset/raw/docs/python/stdlib2/stdlib2_39.md
b4f32c58-122c-549b-a970-74ee294402f5
docs
python
python_stdlib2
39
11
The [`weakref`](../library/weakref.html#module-weakref "weakref: Support for weak references and weak dictionaries.") module provides tools for tracking objects without creating a reference. When the object is no longer needed, it is automatically removed from a weakref table and a callback is triggered for weakref obj...
large_dataset/raw/docs/python/stdlib2/stdlib2_39.md
f7dc3df8-7301-59f8-a330-ffed544a9212
docs
python
python_stdlib2
39
12
Traceback (most recent call last): File "<stdin>", line 1, in <module> d['primary'] # entry was automatically removed File "C:/python39/lib/weakref.py", line 46, in __getitem__ o = self.data[key]() KeyError: 'primary' ``` ## 11.7. Tools for Working with Lists[¶](#tools-for-working-with-lists...
large_dataset/raw/docs/python/stdlib2/stdlib2_39.md
ffd6d199-c850-54c2-948a-45e6e75af006
docs
python
python_stdlib2
39
13
>>> from array import array >>> a = array('H', [4000, 10, 700, 22222]) >>> sum(a) 26932 >>> a[1:3] array('H', [10, 700]) ``` The [`collections`](../library/collections.html#module-collections "collections: Container datatypes") module provides a [`deque()`](../library/collections.html#collections.deque "collections.de...
large_dataset/raw/docs/python/stdlib2/stdlib2_39.md
53090b3d-dc14-59a3-991c-2e9ff967efcd
docs
python
python_stdlib2
39
14
tools such as the [`bisect`](../library/bisect.html#module-bisect "bisect: Array bisection algorithms for binary searching.") module with functions for manipulating sorted lists: ```None >>> import bisect >>> scores = [(100, 'perl'), (200, 'tcl'), (400, 'lua'), (500, 'python')] >>> bisect.insort(scores, (300, 'ruby'))...
large_dataset/raw/docs/python/stdlib2/stdlib2_39.md
07f0a582-eafe-5689-9a9c-b9f87a7545d7
docs
python
python_stdlib2
39
15
>>> [heappop(data) for i in range(3)] # fetch the three smallest entries [-5, 0, 1] ``` ## 11.8. Decimal Floating Point Arithmetic[¶](#decimal-floating-point-arithmetic "Permalink to this headline") The [`decimal`](../library/decimal.html#module-decimal "decimal: Implementation of the General Decimal Arithmetic Spe...
large_dataset/raw/docs/python/stdlib2/stdlib2_39.md
76896179-1ea7-5a8f-9e9e-491f2eeeafbe
docs
python
python_stdlib2
39
16
results in decimal floating point and binary floating point. The difference becomes significant if the results are rounded to the nearest cent: ```None >>> from decimal import * >>> round(Decimal('0.70') * Decimal('1.05'), 2) Decimal('0.74') >>> round(.70 * 1.05, 2) 0.73 ``` The [`Decimal`](../library/decimal.html#de...
large_dataset/raw/docs/python/stdlib2/stdlib2_39.md
1b054b51-7273-538f-b19f-cd17cd5c9633
docs
python
python_stdlib2
39
17
The [`decimal`](../library/decimal.html#module-decimal "decimal: Implementation of the General Decimal Arithmetic Specification.") module provides arithmetic with as much precision as needed: ```None >>> getcontext().prec = 36 >>> Decimal(1) / Decimal(7) Decimal('0.142857142857142857142857142857142857') ```
large_dataset/raw/docs/python/stdlib2/stdlib2_39.md
0f0108e0-4eee-57a2-ad02-a6f91c3a65cd
docs
python
python_stdtypes
310
0
# Built-in Types¶ Source: https://docs.python.org/3.10/library/stdtypes.html Version: 3.10 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_310.md
671bcc6f-a832-5aa1-9a5a-224c602fd5c4
docs
python
python_stdtypes
310
1
## Truth Value Testing[¶](#truth-value-testing "Permalink to this headline") 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 consid...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
a23a714d-2f44-57a3-86f8-574305cde7fd
docs
python
python_stdtypes
310
2
## Boolean Operations — `and`, `or`, `not`[¶](#boolean-operations-and-or-not "Permalink to this headline") These are the Boolean operations, ordered by ascending priority: | Operation | Result | Notes | | --- | --- | --- | | `x or y` | if *x* is true, then *x*, else *y* | (1) | | `x and y` | if *x* is false, then *x*...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
4c461578-dfc6-5795-8b36-85637d428e0d
docs
python
python_stdtypes
310
3
be chained arbitrarily; for example, `x < y <= z` is equivalent to `x < y and y <= z`, except that *y* is evaluated only once (but in both cases *z* is not evaluated at all when `x < y` is found to be false). This table summarizes the comparison operations: | Operation | Meaning | | --- | --- | | `<` | strictly less ...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
50adfc03-8fde-5acf-ab11-8b813f8ae54c
docs
python
python_stdtypes
310
4
Non-identical instances of a class normally compare as non-equal unless the class defines the [`__eq__()`](../reference/datamodel.html#object.__eq__ "object.__eq__") method. Instances of a class cannot be ordered with respect to other instances of the same class, or other types of object, unless the class defines enou...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
7fcacbe3-aa80-5b66-8c73-f7b303d93435
docs
python
python_stdtypes
310
5
customized; also they can be applied to any two objects and never raise an exception. Two more operations with the same syntactic priority, [`in`](../reference/expressions.html#in) and [`not in`](../reference/expressions.html#not-in), are supported by types that are [iterable](../glossary.html#term-iterable) or implem...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
aea0a52f-79a8-5aca-8e47-431ac8a357ca
docs
python
python_stdtypes
310
6
in [`sys.float_info`](sys.html#sys.float_info "sys.float_info"). Complex numbers have a real and imaginary part, which are each a floating point number. To extract these parts from a complex number *z*, use `z.real` and `z.imag`. (The standard library includes the additional numeric types [`fractions.Fraction`](fractio...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
1e3eaabb-a20c-5e2f-a42c-eea4cfbd55db
docs
python
python_stdtypes
310
7
Python fully supports mixed arithmetic: when a binary arithmetic operator has operands of different numeric types, the operand with the “narrower” type is widened to that of the other, where integer is narrower than floating point, which is narrower than complex. A comparison between numbers of different types behaves ...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
663ba808-a088-58b7-9ad8-b8370967b653
docs
python
python_stdtypes
310
8
| `x / y` | quotient of *x* and *y* | | | | `x // y` | floored quotient of *x* and *y* | (1) | | | `x % y` | remainder of `x / y` | (2) | | | `-x` | *x* negated | | | | `+x` | *x* unchanged | | | | `abs(x)` | absolute value or magnitude of *x* | | [`abs()`](functions.html#abs "abs") | | `int(x)` | *x* converte...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
6752e8a4-c1c1-532f-bfd5-8397895010e8
docs
python
python_stdtypes
310
9
integer, though the result’s type is not necessarily 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 `0`. 2. Not for complex numbers. Instead convert to floats using [`abs()`](functions.html#abs "abs") if appropriate. 3. Conv...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
7679f780-236d-56a0-87cf-48df63a96a8d
docs
python
python_stdtypes
310
10
See <https://www.unicode.org/Public/13.0.0/ucd/extracted/DerivedNumericType.txt> for a complete list of code points with the `Nd` property. All [`numbers.Real`](numbers.html#numbers.Real "numbers.Real") types ([`int`](functions.html#int "int") and [`float`](functions.html#float "float")) also include the followi...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
03c77278-009c-5ecc-b79c-d1e4f42d5bfd
docs
python
python_stdtypes
310
11
For additional numeric operations see the [`math`](math.html#module-math "math: Mathematical functions (sin() etc.).") and [`cmath`](cmath.html#module-cmath "cmath: Mathematical functions for complex numbers.") modules. ### Bitwise Operations on Integer Types[¶](#bitwise-operations-on-integer-types "Permalink to this ...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
94e83e4e-50ad-552f-a0e5-5a5f8c9fdb67
docs
python
python_stdtypes
310
12
| `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. Negative shift counts are illegal and cause a [`ValueError`](exceptions.html#ValueError "ValueError") to be raised. 2. A left shift by *n* bits is equivalent to m...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
4b88309d-6102-52e4-b66a-d609d37f7f23
docs
python
python_stdtypes
310
13
class](../glossary.html#term-abstract-base-class). In addition, it provides a few more methods: `int.``bit_length`()[¶](#int.bit_length "Permalink to this definition") : Return the number of bits necessary to represent an integer in binary, excluding the sign and leading zeros: ```None >>> n = -37 >...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
e0593856-3e65-5a3c-bdbc-74d432c49e1b
docs
python
python_stdtypes
310
14
`int.``bit_count`()[¶](#int.bit_count "Permalink to this definition") : Return the number of ones in the binary representation of the absolute value of the integer. This is also known as the population count. Example: ```None >>> n = 19 >>> bin(n) '0b10011' >>> n.bit_count() 3 >>>...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
c0a0e9d1-0cb9-56c5-a13e-07ba90aeca1d
docs
python
python_stdtypes
310
15
``` The integer is represented using *length* bytes. An [`OverflowError`](exceptions.html#OverflowError "OverflowError") is raised if the integer is not representable with the given number of bytes. The *byteorder* argument determines the byte order used to represent the integer. If *byteorder...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
e9f55298-b77b-5476-8e59-3bcf7ecb5cea
docs
python
python_stdtypes
310
16
*classmethod* `int.``from_bytes`(*bytes*, *byteorder*, *\**, *signed=False*)[¶](#int.from_bytes "Permalink 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_310.md
573a1724-0991-5dab-bb5d-39a092ec4d70
docs
python
python_stdtypes
310
17
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. New in version 3.2. `int.``as_integer_ratio`()[¶](#int.as_integer_ratio "Permalink to th...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
595ab4a0-de0c-54d2-a533-7dfa244d6eaa
docs
python
python_stdtypes
310
18
: 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_...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
7f071bc6-5325-52b7-b80a-6a2a32852fae
docs
python
python_stdtypes
310
19
: 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 "Permalink to this definition") : Class method ...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
ac21485e-804f-5741-8a22-1c862157d436
docs
python
python_stdtypes
310
20
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_310.md
a712cbdb-2302-5b09-9554-3576b01cd3ed
docs
python
python_stdtypes
310
21
### Hashing of numeric types[¶](#hashing-of-numeric-types "Permalink to this headline") 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 mo...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
e3de8df0-f6d7-505d-a2f8-1343191f5a1a
docs
python
python_stdtypes
310
22
[`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` attribute of [`sys.hash_info`](sys.html#sys.hash_info "sys.has...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
fdae4445-4cc0-5fe3-96b6-d2317d57514b
docs
python
python_stdtypes
310
23
* 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_310.md
44a32315-d604-554c-9b2c-1491866a4716
docs
python
python_stdtypes
310
24
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_310.md
0f3b09f6-cc2a-5e1d-8ade-478db800f8e4
docs
python
python_stdtypes
310
25
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_310.md
c347d705-77e4-5ffb-8db0-1a01d8f02028
docs
python
python_stdtypes
310
26
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_310.md
3fa88312-a997-50ad-84d3-e83a8ab9ca4d
docs
python
python_stdtypes
310
27
[`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__ "Permalink to this definition") : Return the next item from the [iterator](../glossary.html#term-iterator). If ther...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
51adba95-5a01-5749-8fc8-5672fcd92511
docs
python
python_stdtypes
310
28
[`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 "Permalink to this headline") Python’s [generator](../glossary.html#term-generator)s provide a conv...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
d847b06c-ca6d-5348-be92-10ffea19bc29
docs
python
python_stdtypes
310
29
Additional sequence types tailored for processing of [binary data](#binaryseq) and [text strings](#textseq) are described in dedicated sections. ### Common Sequence Operations[¶](#common-sequence-operations "Permalink to this headline") The operations in the following table are supported by most sequence types, both ...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
6764e8cc-280c-5e8c-af7e-4644c688d919
docs
python
python_stdtypes
310
30
| Operation | Result | Notes | | --- | --- | --- | | `x in s` | `True` if an item of *s* is equal to *x*, else `False` | (1) | | `x not in s` | `False` if an item of *s* is equal to *x*, else `True` | (1) | | `s + t` | the concatenation of *s* and *t* | (6)(7) | | `s * n` or `n * s` | equivalent to adding *s* to itsel...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
a6ca28f7-7a85-5e24-8b6c-5a2a8f41c5cf
docs
python
python_stdtypes
310
31
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 reference.) Forward and reversed iterators over mutable sequences access values usin...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
a25006da-ad27-59c5-b631-fe3be0a4c3b9
docs
python
python_stdtypes
310
32
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 >>> lists = [[]] * 3 >>> lists [[], [], []...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
465e74db-1a8f-57e6-80f2-05b91fefeb01
docs
python
python_stdtypes
310
33
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 sequence of items with index *k* such that `i <= k < j`. If *i* or *j* is greater than `len(s)`, us...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
f7ab685c-7d5b-556e-bdad-f0dc82298196
docs
python
python_stdtypes
310
34
“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 a new object. This means that building up a sequence by repeated concatenation will have a quadratic runtime cost in the total seque...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
6ba34aea-872f-5319-bf98-4bc88cc5165c
docs
python
python_stdtypes
310
35
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 relevant class documentation 7. Some sequence types (such as [`range`](#range "range")) only support item sequenc...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
c4533756-9808-5d00-8f9c-4e00d8f587c4
docs
python
python_stdtypes
310
36
### Immutable Sequence Types[¶](#immutable-sequence-types "Permalink to this headline") The only operation that immutable sequence types generally implement that is not also implemented by mutable sequence types is support for the [`hash()`](functions.html#hash "hash") built-in. This support allows immutable sequence...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
95c03665-2224-530a-bb9c-314ea10fcdae
docs
python
python_stdtypes
310
37
easier to correctly implement these operations on custom sequence types. In the table *s* is an instance of a mutable sequence type, *t* is any iterable object and *x* is an arbitrary object that meets any type and value restrictions imposed by *s* (for example, [`bytearray`](#bytearray "bytearray") only accepts integ...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
68aca465-6c62-5a5d-b01a-ef6ac9c5d75c
docs
python
python_stdtypes
310
38
| `s.extend(t)` or `s += t` | extends *s* with the contents of *t* (for the most part the same as `s[len(s):len(s)] = t`) | | | `s *= n` | updates *s* with its contents repeated *n* times | (6) | | `s.insert(i, x)` | inserts *x* into *s* at the index given by *i* (same as `s[i:i] = [x]`) | | | `s.pop()` or `s.pop(i)`...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
8822b3b1-d4aa-58dd-b74a-1f9abc0530f8
docs
python
python_stdtypes
310
39
side effect, it does not return the reversed sequence. 5. `clear()` and `copy()` are included for consistency with the interfaces of mutable containers that don’t support slicing operations (such as [`dict`](#dict "dict") and [`set`](#set "set")). `copy()` is not part of the [`collections.abc.MutableSequenc...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
534eeb55-8a27-5064-a825-b60a1acd5c22
docs
python
python_stdtypes
310
40
### Lists[¶](#lists "Permalink to this headline") 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 "Permalink to this definition") : Lists may be constructed in several ways:...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
e43ec66f-591c-5720-a8ba-72ff2315850e
docs
python
python_stdtypes
310
41
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](#typesseq-mutable) sequence operations. Lists ...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
6015b1aa-03a6-54d3-8e3a-1aa8f93064f3
docs
python
python_stdtypes
310
42
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` means that list items are sorted directly without calculating a separate ...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
8e27dbf9-9c63-5788-9d6c-f589a352e788
docs
python
python_stdtypes
310
43
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 by department, then by salary grade). F...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
ff096032-ddb1-5b9e-949d-7c929007f497
docs
python
python_stdtypes
310
44
### Tuples[¶](#tuples "Permalink to this headline") Tuples are immutable sequences, typically used to store collections of heterogeneous data (such as the 2-tuples produced by the [`enumerate()`](functions.html#enumerate "enumerate") built-in). Tuples are also used for cases where an immutable sequence of homogeneous ...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
53853c7a-ace1-573f-87ce-eeaabf8af704
docs
python
python_stdtypes
310
45
container that supports iteration, or an iterator object. If *iterable* is already a tuple, it is returned unchanged. For example, `tuple('abc')` returns `('a', 'b', 'c')` and `tuple( [1, 2, 3] )` returns `(1, 2, 3)`. If no argument is given, the constructor creates a new empty tuple, `()`. Not...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
fbeb2d3d-8ec7-505c-9b79-1d7141216c96
docs
python
python_stdtypes
310
46
### Ranges[¶](#ranges "Permalink to this headline") The [`range`](#range "range") type represents an immutable sequence of numbers and is commonly used for looping a specific number of times in [`for`](../reference/compound_stmts.html#for) loops. *class* `range`(*stop*)[¶](#range "Permalink to this definition") *cla...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
e475e5cf-5850-592f-865f-f33800444cf8
docs
python
python_stdtypes
310
47
For a negative *step*, the contents of the range are still determined by the formula `r[i] = start + step*i`, but the constraints are `i >= 0` and `r[i] > stop`. A range object will be empty if `r[0]` does not meet the value constraint. Ranges do support negative indices, but these are interpreted ...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
c2cf1a1c-e5b0-51ce-9662-c4964968e830
docs
python
python_stdtypes
310
48
>>> list(range(0)) [] >>> list(range(1, 0)) [] ``` Ranges implement all of the [common](#typesseq-common) sequence operations except concatenation and repetition (due to the fact that range objects can only represent sequences that follow a strict pattern and repetition and concaten...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
04082961-33a6-5f89-b87f-75ce9ea8ba5f
docs
python
python_stdtypes
310
49
(small) amount of memory, no matter the size of the range it represents (as it only stores the `start`, `stop` and `step` values, calculating individual items and subranges as needed). Range objects implement the [`collections.abc.Sequence`](collections.abc.html#collections.abc.Sequence "collections.abc.Sequence") ABC...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
212d30ac-dd73-5154-bfd4-9ae662838444
docs
python
python_stdtypes
310
50
[`stop`](#range.stop "range.stop") and [`step`](#range.step "range.step") attributes, for example `range(0) == range(2, 1, 3)` or `range(0, 3, 2) == range(0, 4, 2)`.) Changed in version 3.2: Implement the Sequence ABC. Support slicing and negative indices. Test [`int`](functions.html#int "int") objects for membership ...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
9d8a0363-bf4a-540b-83af-8628991277e8
docs
python
python_stdtypes
310
51
## Text Sequence Type — [`str`](#str "str")[¶](#text-sequence-type-str "Permalink to this headline") Textual data in Python is handled with [`str`](#str "str") objects, or *strings*. Strings are immutable [sequences](#typesseq) of Unicode code points. String literals are written in a variety of ways: * Single quotes:...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
b57b9176-ff79-516c-b932-ae5637a4da3f
docs
python
python_stdtypes
310
52
disables most escape sequence processing. Strings may also be created from other objects using the [`str`](#str "str") constructor. Since there is no separate “character” type, indexing a string produces strings of length 1. That is, for a non-empty string *s*, `s[0] == s[0:1]`. There is also no mutable string type,...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
3020b0d8-a7f7-5c0b-a2a5-391e2eb4d004
docs
python
python_stdtypes
310
53
depends on whether *encoding* or *errors* is given, as follows. If neither *encoding* nor *errors* is given, `str(object)` returns [`type(object).__str__(object)`](../reference/datamodel.html#object.__str__ "object.__str__"), which is the “informal” or nicely printable string representation of *obj...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
2242fde2-5ac0-51ff-9028-2171a96fc941
docs
python
python_stdtypes
310
54
[`bytes.decode(encoding, errors)`](#bytes.decode "bytes.decode"). Otherwise, the bytes object underlying the buffer object is obtained before calling [`bytes.decode()`](#bytes.decode "bytes.decode"). See [Binary Sequence Types — bytes, bytearray, memoryview](#binaryseq) and [Buffer Protocol](../c-api/bu...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
0bd1e780-736f-589a-99bd-42014d0c92dc
docs
python
python_stdtypes
310
55
formatted strings, see the [Formatted string literals](../reference/lexical_analysis.html#f-strings) and [Format String Syntax](string.html#formatstrings) sections. In addition, see the [Text Processing Services](text.html#stringservices) section. ### String Methods[¶](#string-methods "Permalink to this headli...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
106725fd-c42a-5311-9877-b20376d4e9b7
docs
python
python_stdtypes
310
56
The [Text Processing Services](text.html#textservices) section of the standard library covers a number of other modules that provide various text related utilities (including regular expression support in the [`re`](re.html#module-re "re: Regular expression operations.") module). `str.``capitalize`()[¶](#str.capitaliz...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
823d495d-b8e6-59fd-9bec-3f820e1120cc
docs
python
python_stdtypes
310
57
lowercase letter `'ß'` is equivalent to `"ss"`. Since it is already lowercase, [`lower()`](#str.lower "str.lower") would do nothing to `'ß'`; [`casefold()`](#str.casefold "str.casefold") converts it to `"ss"`. The casefolding algorithm is described in section 3.13 of the Unicode Standard. New ...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md
22b389de-7ac6-56bc-be05-436df9cf119a
docs
python
python_stdtypes
310
58
which is the length of the string plus one. `str.``encode`(*encoding='utf-8'*, *errors='strict'*)[¶](#str.encode "Permalink to this definition") : Return the string encoded to [`bytes`](#bytes "bytes"). *encoding* defaults to `'utf-8'`; see [Standard Encodings](codecs.html#standard-encodings) for possib...
large_dataset/raw/docs/python/stdtypes/stdtypes_310.md