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 |
|---|---|---|---|---|---|---|---|
41a51167-bd31-52bc-8acb-a055017da319 | docs | python | python_stdtypes | 314 | 154 | digits are those byte values in the sequence `b'0123456789'`.
For example:
```None
>>> b'ABCabc1'.isalnum()
True
>>> b'ABC abc1'.isalnum()
False
```
bytes.isalpha()[¶](#bytes.isalpha "Link to this definition")
bytearray.isalpha()[¶](#bytearray.isalpha "Link to this definition")
: R... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
76231ff2-6408-5492-abf0-75a46c4cb67b | docs | python | python_stdtypes | 314 | 155 | bytes.isdigit()[¶](#bytes.isdigit "Link to this definition")
bytearray.isdigit()[¶](#bytearray.isdigit "Link to this definition")
: Return `True` if all bytes in the sequence are ASCII decimal digits
and the sequence is not empty, `False` otherwise. ASCII decimal digits are
those byte values in the sequence ... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
e55a099c-9982-51dc-ae76-dc7b2adf9d42 | docs | python | python_stdtypes | 314 | 156 | are those byte values in the sequence `b'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`.
bytes.isspace()[¶](#bytes.isspace "Link to this definition")
bytearray.isspace()[¶](#bytearray.isspace "Link to this definition")
: Return `True` if all bytes in the sequence are ASCII whitespace and the
sequence is not empty, `False` ot... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
359bcceb-caeb-57ef-a416-3010a7e86787 | docs | python | python_stdtypes | 314 | 157 | bytearray.isupper()[¶](#bytearray.isupper "Link to this definition")
: Return `True` if there is at least one uppercase alphabetic ASCII character
in the sequence and no lowercase ASCII characters, `False` otherwise.
For example:
```None
>>> b'HELLO WORLD'.isupper()
True
>>> b'Hello world'.i... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
3bce177a-1788-5824-8c0e-7e3fa0fd8469 | docs | python | python_stdtypes | 314 | 158 | `b'abcdefghijklmnopqrstuvwxyz'`. Uppercase ASCII characters
are those byte values in the sequence `b'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`.
Note
The bytearray version of this method does *not* operate in place - it
always produces a new object, even if no changes were made.
bytes.splitlines(*keepends=Fals... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
5c5d0934-6737-557a-802b-c5ffe815da6d | docs | python | python_stdtypes | 314 | 159 | Unlike [`split()`](#bytes.split "bytes.split") when a delimiter string *sep* is given, this
method returns an empty list for the empty string, and a terminal line
break does not result in an extra line:
```None
>>> b"".split(b'\n'), b"Two lines\n".split(b'\n')
([b''], [b'Two lines', b''])
>... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
fbb28626-53ae-5585-902c-f72dee27e9c5 | docs | python | python_stdtypes | 314 | 160 | Unlike [`str.swapcase()`](#str.swapcase "str.swapcase"), it is always the case that
`bin.swapcase().swapcase() == bin` for the binary versions. Case
conversions are symmetrical in ASCII, even though that is not generally
true for arbitrary Unicode code points.
Note
The bytearray version of thi... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
4c1a8ed3-a961-5eb2-b05b-afa7b3aa8b9b | docs | python | python_stdtypes | 314 | 161 | are those byte values in the sequence `b'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`.
All other byte values are uncased.
The algorithm uses a simple language-independent definition of a word as
groups of consecutive letters. The definition works in many contexts but
it means that apostrophes in contractions and p... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
6dcddac3-5709-588e-9428-f0d8ceb7b9a2 | docs | python | python_stdtypes | 314 | 162 | The bytearray version of this method does *not* operate in place - it
always produces a new object, even if no changes were made.
bytes.upper()[¶](#bytes.upper "Link to this definition")
bytearray.upper()[¶](#bytearray.upper "Link to this definition")
: Return a copy of the sequence with all the lowercase A... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
bfbed24c-6ddf-5804-ab13-0a242ab3f7ac | docs | python | python_stdtypes | 314 | 163 | : Return a copy of the sequence left filled with ASCII `b'0'` digits to
make a sequence of length *width*. A leading sign prefix (`b'+'`/
`b'-'`) is handled by inserting the padding *after* the sign character
rather than before. For [`bytes`](#bytes "bytes") objects, the original sequence is
returned ... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
cef88247-cf9b-5d8b-9315-109601b63f42 | docs | python | python_stdtypes | 314 | 164 | Bytes objects (`bytes`/`bytearray`) have one unique built-in operation:
the `%` operator (modulo).
This is also known as the bytes *formatting* or *interpolation* operator.
Given `format % values` (where *format* is a bytes object), `%` conversion
specifications in *format* are replaced with zero or more elements of *v... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
af4aca75-59f7-53c2-b743-d79ce69fe0d1 | docs | python | python_stdtypes | 314 | 165 | 3. Conversion flags (optional), which affect the result of some conversion
types.
4. Minimum field width (optional). If specified as an `'*'` (asterisk), the
actual width is read from the next element of the tuple in *values*, and the
object to convert comes after the minimum field width and optional precision... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
f7b1355c-3001-571e-82b9-96ed20905202 | docs | python | python_stdtypes | 314 | 166 | ... {b'language': b"Python", b"number": 2})
b'Python has 002 quote types.'
```
In this case no `*` specifiers may occur in a format (since they require a
sequential parameter list).
The conversion flag characters are:
| Flag | Meaning |
| --- | --- |
| `'#'` | The value conversion will use the “alternate form”... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
5f73bad9-d6a6-5986-ba05-759855d757c8 | docs | python | python_stdtypes | 314 | 167 | | `'i'` | Signed integer decimal. | |
| `'o'` | Signed octal value. | (1) |
| `'u'` | Obsolete type – it is identical to `'d'`. | (8) |
| `'x'` | Signed hexadecimal (lowercase). | (2) |
| `'X'` | Signed hexadecimal (uppercase). | (2) |
| `'e'` | Floating-point exponential format (lowercase). | (3) |
| `'E'` | Floating... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
f0ceedbb-0f5b-5c0b-b363-2e153f9f7533 | docs | python | python_stdtypes | 314 | 168 | | `'b'` | Bytes (any object that follows the [buffer protocol](../c-api/buffer.html#bufferobjects) or has [`__bytes__()`](../reference/datamodel.html#object.__bytes__ "object.__bytes__")). | (5) |
| `'s'` | `'s'` is an alias for `'b'` and should only be used for Python2/3 code bases. | (6) |
| `'a'` | Bytes (converts a... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
7fb91eb6-c41c-5a18-8602-2da9ce0e4530 | docs | python | python_stdtypes | 314 | 169 | The precision determines the number of digits after the decimal point and
defaults to 6.
4. The alternate form causes the result to always contain a decimal point, and
trailing zeroes are not removed as they would otherwise be.
The precision determines the number of significant digits before and after the
... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
d4b766f0-798d-5103-b274-7097417621eb | docs | python | python_stdtypes | 314 | 170 | ### Memory Views[¶](#memory-views "Link to this heading")
[`memoryview`](#memoryview "memoryview") objects allow Python code to access the internal data
of an object that supports the [buffer protocol](../c-api/buffer.html#bufferobjects) without
copying.
*class* memoryview(*object*)[¶](#memoryview "Link to this defin... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
cfcecde2-dc6e-52e0-9611-28c0f69c3711 | docs | python | python_stdtypes | 314 | 171 | > `len(view)` is equal to the length of [`tolist`](#memoryview.tolist "memoryview.tolist"), which
> is the nested list representation of the view. If `view.ndim = 1`,
> this is equal to the number of elements in the view.
>
> Changed in version 3.12: If `view.ndim == 0`, `len(view)` now raises [`Typ... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
c0e99805-0c6f-5a3b-91ea-612de962a331 | docs | python | python_stdtypes | 314 | 172 | > from the [`struct`](struct.html#module-struct "struct: Interpret bytes as packed binary data.") module, indexing with an integer or a tuple of
> integers is also supported and returns a single *element* with
> the correct type. One-dimensional memoryviews can be indexed
> with an integer or a one-inte... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
67d1a9f2-9190-5037-a384-05f1973cd85d | docs | python | python_stdtypes | 314 | 173 | > ```None
> >>> data = bytearray(b'abcefg')
> >>> v = memoryview(data)
> >>> v.readonly
> False
> >>> v[0] = ord(b'z')
> >>> data
> bytearray(b'zbcefg')
> >>> v[1:4] = b'123'
> >>> data
> bytearray(b'z123fg')
> >>> v[2:3] = b'spam'
> Traceback (most recent call last):... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
4cc863ba-7b3b-53ee-8074-559c24ebe2b1 | docs | python | python_stdtypes | 314 | 174 | > Changed in version 3.3: One-dimensional memoryviews can now be sliced.
> One-dimensional memoryviews with formats ‘B’, ‘b’ or ‘c’ are now [hashable](../glossary.html#term-hashable).
>
> Changed in version 3.4: memoryview is now registered automatically with
> [`collections.abc.Sequence`](collectio... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
9afa7e54-bc8a-500f-ac36-d0c40dedf4b0 | docs | python | python_stdtypes | 314 | 175 | > respective format codes are interpreted using [`struct`](struct.html#module-struct "struct: Interpret bytes as packed binary data.") syntax.
>
> For the subset of [`struct`](struct.html#module-struct "struct: Interpret bytes as packed binary data.") format strings currently supported by
> ... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
7f5772fb-bd1c-5b2f-9270-8ecb70056f6f | docs | python | python_stdtypes | 314 | 176 | > If either format string is not supported by the [`struct`](struct.html#module-struct "struct: Interpret bytes as packed binary data.") module,
> then the objects will always compare as unequal (even if the format
> strings and buffer contents are identical):
>
> ```None
> >... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
632015e9-ee94-5148-ad1e-3b2b8d30cc56 | docs | python | python_stdtypes | 314 | 177 | > tobytes(*order='C'*)[¶](#memoryview.tobytes "Link to this definition")
> : Return the data in the buffer as a bytestring. This is equivalent to
> calling the [`bytes`](#bytes "bytes") constructor on the memoryview.
>
> ```None
> >>> m = memoryview(b"abc")
> >>> m.tobytes(... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
2e279fe1-c2f4-53bc-a119-5394ec41f38a | docs | python | python_stdtypes | 314 | 178 | > views, ‘A’ returns an exact copy of the physical memory. In particular,
> in-memory Fortran order is preserved. For non-contiguous views, the
> data is converted to C first. *order=None* is the same as *order=’C’*.
>
> hex(*\**, *bytes\_per\_sep=1*)[¶](#memoryview.hex "Link to this def... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
b3ba855b-1539-51c3-aecd-706a9d7aa777 | docs | python | python_stdtypes | 314 | 179 | > : Return the data in the buffer as a list of elements.
>
> ```None
> >>> memoryview(b'abc').tolist()
> [97, 98, 99]
> >>> import array
> >>> a = array.array('d', [1.1, 2.2, 3.3])
> >>> m = memoryview(a)
> >>> m.tolist()
> [1.1, 2.2, 3.3]
> ... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
baa11474-4465-5e32-bee4-6a28585096d1 | docs | python | python_stdtypes | 314 | 180 | > Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: cannot modify read-only memory
> >>> m[0] = 43
> >>> mm.tolist()
> [43, 98, 99]
> ```
>
> Added in version 3.8.
>
> release()[¶](#memoryview.release "Link... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
137e7b99-5194-58d6-92be-a46f4017c4ed | docs | python | python_stdtypes | 314 | 181 | > ```None
> >>> m = memoryview(b'abc')
> >>> m.release()
> >>> m[0]
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> ValueError: operation forbidden on released memoryview object
> ```
>
> The context management pr... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
b9fb743e-af60-55d8-8b16-9711bcdbc3f6 | docs | python | python_stdtypes | 314 | 182 | > will be one-dimensional. The return value is a new memoryview, but
> the buffer itself is not copied. Supported casts are 1D -> C-[contiguous](../glossary.html#term-contiguous)
> and C-contiguous -> 1D.
>
> The destination format is restricted to a single element native format in
... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
d14afe18-45eb-59c6-8e29-7cad257873ee | docs | python | python_stdtypes | 314 | 183 | > 'B'
> >>> y.itemsize
> 1
> >>> len(y)
> 24
> >>> y.nbytes
> 24
> ```
>
> Cast 1D/unsigned bytes to 1D/char:
>
> ```None
> >>> b = bytearray(b'zyz')
> >>> x = memoryview(b)
> >>> x[0] = b'a'
> Traceb... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
bb4f39da-f7ed-5cdb-8872-694d1bb296c2 | docs | python | python_stdtypes | 314 | 184 | > >>> z = y.cast('b')
> >>> z.format
> 'b'
> >>> z.itemsize
> 1
> >>> len(z)
> 48
> >>> z.nbytes
> 48
> ```
>
> Cast 1D/unsigned long to 2D/unsigned long:
>
> ```None
> >>> buf = struct.pack("L"*6, *list(rang... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
d741b977-58ab-5fdc-8888-84c506542368 | docs | python | python_stdtypes | 314 | 185 | : > Return the index of the first occurrence of *value* (at or after
> index *start* and before index *stop*).
>
> Raises a [`ValueError`](exceptions.html#ValueError "ValueError") if *value* cannot be found.
>
> Added in version 3.14.
There are also several readonl... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
1be5a12e-6be4-5948-8b4f-009f73de1470 | docs | python | python_stdtypes | 314 | 186 | >>> a = array.array('i', [1,2,3,4,5])
>>> m = memoryview(a)
>>> len(m)
5
>>> m.nbytes
20
>>> y = m[::2]
>>> len(y)
3
>>> y.nbytes
12
>>> len(y.tobytes())
12
... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
e2515cba-491c-58c0-b6bf-9095752caf93 | docs | python | python_stdtypes | 314 | 187 | : A string containing the format (in [`struct`](struct.html#module-struct "struct: Interpret bytes as packed binary data.") module style) for each
element in the view. A memoryview can be created from exporters with
arbitrary format strings, but some methods (e.g. [`tolist()`](#memoryv... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
982a7c22-cd07-5926-a64b-dc4cc84f8306 | docs | python | python_stdtypes | 314 | 188 | ndim[¶](#memoryview.ndim "Link to this definition")
: An integer indicating how many dimensions of a multi-dimensional array the
memory represents.
shape[¶](#memoryview.shape "Link to this definition")
: A tuple of integers the length of [`ndim`](#memoryview.ndim "memory... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
1412b3a4-84a7-505e-9f3f-2619706d1f08 | docs | python | python_stdtypes | 314 | 189 | c\_contiguous[¶](#memoryview.c_contiguous "Link to this definition")
: A bool indicating whether the memory is C-[contiguous](../glossary.html#term-contiguous).
Added in version 3.3.
f\_contiguous[¶](#memoryview.f_contiguous "Link to this definition")
: A bool indicatin... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
3b3e8d6c-097d-5db4-a9f3-084a89a7b3e2 | docs | python | python_stdtypes | 314 | 190 | computing mathematical operations such as intersection, union, difference, and
symmetric difference.
(For other containers see the built-in [`dict`](#dict "dict"), [`list`](#list "list"),
and [`tuple`](#tuple "tuple") classes, and the [`collections`](collections.html#module-collections "collections: Container datatypes... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
140cdddb-283c-575c-9b0b-59d9a6a90a60 | docs | python | python_stdtypes | 314 | 191 | The [`frozenset`](#frozenset "frozenset") type is immutable and [hashable](../glossary.html#term-hashable) —
its contents cannot be altered after it is created;
it can therefore be used as a dictionary key or as an element of another set.
Non-empty sets (not frozensets) can be created by placing a comma-separated list... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
093d2965-d38c-574a-a5f0-fad6ccbc2c66 | docs | python | python_stdtypes | 314 | 192 | * Use a comma-separated list of elements within braces: `{'jack', 'sjoerd'}`
* Use a set comprehension: `{c for c in 'abracadabra' if c not in 'abc'}`
* Use the type constructor: `set()`, `set('foobar')`, `set(['a', 'b', 'foo'])`
Instances of [`set`](#set "set") and [`frozenset`](#frozenset "frozenset") provide the fo... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
072ae97a-c0ec-5714-858b-228b6bed4bd5 | docs | python | python_stdtypes | 314 | 193 | : Test whether every element in the set is in *other*.
set < other
: Test whether the set is a proper subset of *other*, that is,
`set <= other and set != other`.
frozenset.issuperset(*other*, */*)[¶](#frozenset.issuperset "Link to this definition")
set.issuperset(*other*, */*)[¶](#set.issuperset "Link to th... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
944ec145-aed1-5dc4-86a6-9412a228c36b | docs | python | python_stdtypes | 314 | 194 | frozenset.difference(*\*others*)[¶](#frozenset.difference "Link to this definition")
set.difference(*\*others*)[¶](#set.difference "Link to this definition")
set - other - ...
: Return a new set with elements in the set that are not in the others.
frozenset.symmetric\_difference(*other*, */*)[¶](#frozenset.symmetr... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
43f5ad31-a1b4-5635-8efc-742ece735c5a | docs | python | python_stdtypes | 314 | 195 | [`intersection()`](#frozenset.intersection "frozenset.intersection"), [`difference()`](#frozenset.difference "frozenset.difference"), [`symmetric_difference()`](#frozenset.symmetric_difference "frozenset.symmetric_difference"), [`issubset()`](#frozenset.issubset "frozenset.issubset"), and
[`issuperset()`](#frozenset.is... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
51ac17e5-d79a-570c-8242-a0809cf6db95 | docs | python | python_stdtypes | 314 | 196 | is not equal). A set is greater than another set if and only if the first set
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'... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
89387719-c02a-55bd-9202-38648c8a17f2 | docs | python | python_stdtypes | 314 | 197 | 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"):
set.update(*\*others*... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
bb354ed5-4bc4-51a8-acb6-4efd718f944e | docs | python | python_stdtypes | 314 | 198 | set.add(*elem*, */*)[¶](#set.add "Link to this definition")
: Add element *elem* to the set.
set.remove(*elem*, */*)[¶](#set.remove "Link to this definition")
: Remove element *elem* from the set. Raises [`KeyError`](exceptions.html#KeyError "KeyError") if *elem* is
not contained in the set.
set.discard(*elem... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
1484668b-c3cd-52f9-8099-8530a96b7c71 | docs | python | python_stdtypes | 314 | 199 | [`symmetric_difference_update()`](#set.symmetric_difference_update "set.symmetric_difference_update") methods will accept any iterable as an
argument.
Note, the *elem* argument to the [`__contains__()`](../reference/datamodel.html#object.__contains__ "object.__contains__"),
[`remove()`](#set.remove "set.remove"), and
... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
6e5bac44-1d53-52f9-8675-5a2a2b520981 | docs | python | python_stdtypes | 314 | 200 | A dictionary’s keys are *almost* arbitrary values. Values that are not
[hashable](../glossary.html#term-hashable), that is, values containing lists, dictionaries or other
mutable types (that are compared by value rather than by object identity) may
not be used as keys.
Values that compare equal (such as `1`, `1.0`, and... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
a7c0092d-4df2-58df-8f41-a345a3d78a94 | docs | python | python_stdtypes | 314 | 201 | `dict([('foo', 100), ('bar', 200)])`, `dict(foo=100, bar=200)`
If no positional argument is given, an empty dictionary is created.
If a positional argument is given and it defines a `keys()` method, a
dictionary is created by calling [`__getitem__()`](../reference/datamodel.html#object.__getitem__ "o... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
78f51ed7-221d-50bb-9304-2f86f746d2ee | docs | python | python_stdtypes | 314 | 202 | being added is already present, the value from the keyword argument
replaces the value from the positional argument.
Dictionaries compare equal if and only if they have the same `(key,
value)` pairs (regardless of ordering). Order comparisons (‘<’, ‘<=’, ‘>=’, ‘>’) raise
[`TypeError`](exceptions.ht... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
7e463836-106c-5bd6-bf4b-b7b26f3cc135 | docs | python | python_stdtypes | 314 | 203 | Dictionaries preserve insertion order. Note that updating a key does not
affect the order. Keys added after deletion are inserted at the end.
```None
>>> d = {"one": 1, "two": 2, "three": 3, "four": 4}
>>> d
{'one': 1, 'two': 2, 'three': 3, 'four': 4}
>>> list(d)
['one', 'two', 'three',... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
a1b4f553-88bf-531f-bbc5-6a3095f2d029 | docs | python | python_stdtypes | 314 | 204 | : 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 dict defines a method [`__missing__()`](../reference/datamodel.html#object.__missing__ "object.__missing__") and *key*
is not present, the `d[ke... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
21a35b5d-5bae-50ab-ad58-e22ea615115a | docs | python | python_stdtypes | 314 | 205 | ... def __missing__(self, key):
... return 0
...
>>> c = Counter()
>>> c['red']
0
>>> c['red'] += 1
>>> c['red']
1
```
The example above shows part of the implementation of
[`collections.Counter`](collections.ht... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
24a605bf-304b-5b66-8341-cfeee6270508 | docs | python | python_stdtypes | 314 | 206 | clear()[¶](#dict.clear "Link to this definition")
: Remove all items from the dictionary.
copy()[¶](#dict.copy "Link to this definition")
: Return a shallow copy of the dictionary.
*classmethod* fromkeys(*iterable*, *value=None*, */*)[¶](#dict.fromkeys "Link to this definition")
: Create... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
7352302f-913c-5c8f-9afd-16fc5f47b1c3 | docs | python | python_stdtypes | 314 | 207 | If *default* is not given, it defaults to `None`, so that this method
never raises a [`KeyError`](exceptions.html#KeyError "KeyError").
items()[¶](#dict.items "Link to this definition")
: Return a new view of the dictionary’s items (`(key, value)` pairs).
See the [documentation of vie... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
fb679710-1ea1-5327-9a19-a55c702e14eb | docs | python | python_stdtypes | 314 | 208 | [`popitem()`](#dict.popitem "dict.popitem") is useful to destructively iterate over a dictionary, as
often used in set algorithms. If the dictionary is empty, calling
[`popitem()`](#dict.popitem "dict.popitem") raises a [`KeyError`](exceptions.html#KeyError "KeyError").
Changed in versi... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
f8252d9b-a47c-55a1-9e08-f895cf01b42e | docs | python | python_stdtypes | 314 | 209 | update(*iterable*, */*, *\*\*kwargs*)
: Update the dictionary with the key/value pairs from *mapping* or *iterable* and *kwargs*, overwriting
existing keys. Return `None`.
[`update()`](#dict.update "dict.update") accepts either another object with a `keys()` method (in
which case [`__... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
5edced9d-bc65-58d9-8e21-9f1c83da86b0 | docs | python | python_stdtypes | 314 | 210 | `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_314.md |
5fc9ba84-fa05-5574-a03e-2b65322d976a | docs | python | python_stdtypes | 314 | 211 | >>> 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_314.md |
df6a1326-3a37-5348-9a74-604a5de29987 | docs | python | python_stdtypes | 314 | 212 |
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_314.md |
d2916166-061e-5feb-9606-f9f5a962a202 | docs | python | python_stdtypes | 314 | 213 | : 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_314.md |
acda974a-7ac3-5e46-8366-904327ab3a27 | docs | python | python_stdtypes | 314 | 214 | >>> 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_314.md |
f2c8deb3-25f1-5db0-953e-e08a0b2b4390 | docs | python | python_stdtypes | 314 | 215 | ## 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_314.md |
5c0e079a-7aad-51bd-b710-57a825705f53 | docs | python | python_stdtypes | 314 | 216 | 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_314.md |
1d015338-3839-5a43-86bc-3b29e7b5e81f | docs | python | python_stdtypes | 314 | 217 | 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_314.md |
7c4f0e25-72cf-538a-b1b8-7d8af4761403 | docs | python | python_stdtypes | 314 | 218 | 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_314.md |
30226bd8-ed3a-5afc-9fd9-6e20d006666e | docs | python | python_stdtypes | 314 | 219 | 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_314.md |
1a848232-8d98-52cb-aaa5-a1236b10973c | docs | python | python_stdtypes | 314 | 220 | ### 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_314.md |
4f553b1a-5c30-51f1-9d53-00263151c30b | docs | python | python_stdtypes | 314 | 221 | 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_314.md |
c949c7bc-6a63-5e35-a323-77cac8ab0dde | docs | python | python_stdtypes | 314 | 222 | 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_314.md |
8b5fba68-706b-50df-b708-54fff449bebf | docs | python | python_stdtypes | 314 | 223 | 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_314.md |
0ae131de-0ebe-52f4-bc65-64c9fdd73802 | docs | python | python_stdtypes | 314 | 224 | 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_314.md |
5c2b58dc-0a47-54c1-991f-f4b16ce3db94 | docs | python | python_stdtypes | 314 | 225 | 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_314.md |
11a225e3-47c0-5da8-9c86-e58427624f12 | docs | python | python_stdtypes | 314 | 226 | * [`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_314.md |
7e3804fe-4989-535d-9404-045a3c2476a2 | docs | python | python_stdtypes | 314 | 227 | * [`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_314.md |
4f89678d-66c2-5fd1-a7cc-0f8d39b1f579 | docs | python | python_stdtypes | 314 | 228 | * [`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_314.md |
c82d96b4-555f-5fb0-8d96-b339fba3a608 | docs | python | python_stdtypes | 314 | 229 | * [`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_314.md |
f634ba32-072e-5d90-858d-abafc44e6ffe | docs | python | python_stdtypes | 314 | 230 | * [`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_314.md |
e8da442f-d4c4-57ac-be78-ea35e79c6a34 | docs | python | python_stdtypes | 314 | 231 | 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_314.md |
e4f216ff-9681-5359-ace8-7359170f7300 | docs | python | python_stdtypes | 314 | 232 | [`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_314.md |
58a08afd-58b9-5e9d-968a-24d68ab66820 | docs | python | python_stdtypes | 314 | 233 | [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_314.md |
9afc5bcc-5f84-5b0d-ba42-5e33b148f194 | docs | python | python_stdtypes | 314 | 234 | [`int`](functions.html#int "int") or [`float`](functions.html#float "float"):
```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 exampl... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
eb9fad9f-8f80-5857-a2a1-9ad413ea1cc3 | docs | python | python_stdtypes | 314 | 235 | * It creates instances of [`typing.Union`](typing.html#typing.Union "typing.Union"):
```None
int | str == typing.Union[int, str]
type(int | str) is typing.Union
```
* Optional types can be spelled as a union with `None`:
```None
str | None == typing.Optional[str]
```
... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
4870a84c-725a-5014-881a-aecd48f8c098 | docs | python | python_stdtypes | 314 | 236 | The user-exposed type for the union object can be accessed from
[`typing.Union`](typing.html#typing.Union "typing.Union") and used for [`isinstance()`](functions.html#isinstance "isinstance") checks:
```None
>>> import typing
>>> isinstance(int | str, typing.Union)
True
>>> typing.Union()
Traceback (most recent call l... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
3904d40e-d05e-5ab4-b491-84d5c4a17f38 | docs | python | python_stdtypes | 314 | 237 | Changed in version 3.14: Union objects are now instances of [`typing.Union`](typing.html#typing.Union "typing.Union"). Previously, they were instances
of [`types.UnionType`](types.html#types.UnionType "types.UnionType"), which remains an alias for [`typing.Union`](typing.html#typing.Union "typing.Union").
## Other Bui... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
37c6a7a7-0900-5a5b-b5f8-222471cc62c1 | docs | python | python_stdtypes | 314 | 238 | A special attribute of every module is [`__dict__`](../reference/datamodel.html#object.__dict__ "object.__dict__"). This is the
dictionary containing the module’s symbol table. Modifying this dictionary will
actually change the module’s symbol table, but direct assignment to the
[`__dict__`](../reference/datamodel.html... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
c567440d-bf94-5118-9346-b2114d9ca0d7 | docs | python | python_stdtypes | 314 | 239 | See [Objects, values and types](../reference/datamodel.html#objects) and [Class definitions](../reference/compound_stmts.html#class) for these.
### Functions[¶](#functions "Link to this heading")
Function objects are created by function definitions. The only operation on a
function object is to call it: `func(argumen... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
751f5821-b3ab-5bf8-95a0-78c5f9d27a87 | docs | python | python_stdtypes | 314 | 240 | Built-in methods are described with the types that support them.
If you access a method (a function defined in a class namespace) through an
instance, you get a special object: a *bound method* (also called
[instance method](../reference/datamodel.html#instance-methods)) object. When called, it will add
the `self` arg... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
1102d6dc-bb59-5aa6-aee9-a6a3e75aad97 | docs | python | python_stdtypes | 314 | 241 | underlying function object ([`method.__func__`](../reference/datamodel.html#method.__func__ "method.__func__")), setting method attributes on
bound methods is disallowed. Attempting to set an attribute on a method
results in an [`AttributeError`](exceptions.html#AttributeError "AttributeError") being raised. In order t... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
068b6339-1794-5445-b62b-99ca14d0e2d6 | docs | python | python_stdtypes | 314 | 242 | ### Code Objects[¶](#code-objects "Link to this heading")
Code objects are used by the implementation to represent “pseudo-compiled”
executable Python code such as a function body. They differ from function
objects because they don’t contain a reference to their global execution
environment. Code objects are returned ... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
34fcd253-7e1b-5274-afa1-f2d97dd410bf | docs | python | python_stdtypes | 314 | 243 | string) to the [`exec()`](functions.html#exec "exec") or [`eval()`](functions.html#eval "eval") built-in functions.
See [The standard type hierarchy](../reference/datamodel.html#types) for more information.
### Type Objects[¶](#type-objects "Link to this heading")
Type objects represent the various object types. An ... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
f3cf193f-cacd-5c30-b72f-3d619e8fd647 | docs | python | python_stdtypes | 314 | 244 | ### The Ellipsis Object[¶](#the-ellipsis-object "Link to this heading")
This object is commonly used to indicate that something is omitted.
It supports no special operations. There is exactly one ellipsis object, named
[`Ellipsis`](constants.html#Ellipsis "Ellipsis") (a built-in name). `type(Ellipsis)()` produces the
... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
1b5b75cc-7f91-5030-b716-3d57029a3068 | docs | python | python_stdtypes | 314 | 245 | * Doctest’s [`ELLIPSIS`](doctest.html#doctest.ELLIPSIS "doctest.ELLIPSIS"), as a pattern for missing content.
* The default Python prompt of the [interactive](../glossary.html#term-interactive) shell when partial input is incomplete.
Lastly, the Python documentation often uses three dots in conventional English
usage ... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
82d9789e-4407-5d9a-8947-cff361ec067e | docs | python | python_stdtypes | 314 | 246 | ### Internal Objects[¶](#internal-objects "Link to this heading")
See [The standard type hierarchy](../reference/datamodel.html#types) for this information. It describes
[stack frame objects](../reference/datamodel.html#frame-objects),
[traceback objects](../reference/datamodel.html#traceback-objects), and slice objec... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
afbe6c49-62eb-5c78-a9e4-2f8441c36302 | docs | python | python_stdtypes | 314 | 247 | definition.\_\_module\_\_[¶](#definition.__module__ "Link to this definition")
: The name of the module in which a class or function was defined.
definition.\_\_doc\_\_[¶](#definition.__doc__ "Link to this definition")
: The documentation string of a class or function, or `None` if undefined.
definition.\_\_type\... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
49298004-b796-5dba-a980-e7e3235ad0d8 | docs | python | python_stdtypes | 314 | 248 | other non-power-of-two number bases. Hexadecimal, octal, and binary conversions
are unlimited. The limit can be configured.
The [`int`](functions.html#int "int") type in CPython is an arbitrary length number stored in binary
form (commonly known as a “bignum”). There exists no algorithm that can convert
a string to a ... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
eabe8bf1-7bd9-57f4-8473-28968081398f | docs | python | python_stdtypes | 314 | 249 | When an operation would exceed the limit, a [`ValueError`](exceptions.html#ValueError "ValueError") is raised:
```None
>>> import sys
>>> sys.set_int_max_str_digits(4300) # Illustrative, this is the default.
>>> _ = int('2' * 5432)
Traceback (most recent call last):
...
ValueError: Exceeds the limit (4300 digits) for... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
bc504009-d5e0-55ae-be3b-31b0d6c6a091 | docs | python | python_stdtypes | 314 | 250 | [`sys.int_info.str_digits_check_threshold`](sys.html#sys.int_info "sys.int_info").
Verification:
```None
>>> import sys
>>> assert sys.int_info.default_max_str_digits == 4300, sys.int_info
>>> assert sys.int_info.str_digits_check_threshold == 640, sys.int_info
>>> msg = int('578966293710682886880994035146873798396722... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
a054b51f-240b-5079-9b6e-754ae25ecd0a | docs | python | python_stdtypes | 314 | 251 | 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.from_bytes") and [`int.to_bytes()`](#int.to_bytes "int.to_bytes").
* [`hex()`](functions.html#hex "hex"), [`oct()`](functions.html#oct "oct"), [`bin()`](fun... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
b0f6fab3-d524-5832-8282-1368d113234c | docs | python | python_stdtypes | 314 | 252 | * [`-X int_max_str_digits`](../using/cmdline.html#cmdoption-X), e.g.
`python3 -X int_max_str_digits=640`
* [`sys.flags.int_max_str_digits`](sys.html#sys.flags.int_max_str_digits "sys.flags.int_max_str_digits") contains the value of
[`PYTHONINTMAXSTRDIGITS`](../using/cmdline.html#envvar-PYTHONINTMAXSTRDIGITS) or [`-... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
84742a5f-01b5-5c59-a8c5-904bdcb70948 | docs | python | python_stdtypes | 314 | 253 | * [`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 setter for the interpreter-wide limit. Subinterpreters have
their own limit.
Information about... | large_dataset/raw/docs/python/stdtypes/stdtypes_314.md |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.