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 |
|---|---|---|---|---|---|---|---|
65b4269a-6ee5-5088-89c6-8afea3a005d5 | docs | python | python_stdtypes | 38 | 140 | ... _fields_ = [("x", c_long), ("y", c_long)]
...
>>> point = BEPoint(100, 200)
>>> a = memoryview(point)
>>> b = memoryview(point)
>>> a == point
False
>>> a == b
False
```
Note that, as with floating point numbers, `v is w` d... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
6184b6c3-f1c3-5a69-ae60-b4de781aa9e1 | docs | python | python_stdtypes | 38 | 141 | representation with all elements converted to bytes. [`tobytes()`](#memoryview.tobytes "memoryview.tobytes")
supports all format strings, including those that are not in
[`struct`](struct.html#module-struct "struct: Interpret bytes as packed binary data.") module syntax.
New in version ... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
0de78222-8563-577c-881d-1a59f73e8412 | docs | python | python_stdtypes | 38 | 142 | New in version 3.5.
Changed in version 3.8: Similar to [`bytes.hex()`](#bytes.hex "bytes.hex"), [`memoryview.hex()`](#memoryview.hex "memoryview.hex") now supports
optional *sep* and *bytes\_per\_sep* parameters to insert separators
between bytes in the hex output.
`tolist`()[¶](#m... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
35bf0325-8687-531f-850c-f500f38a8c92 | docs | python | python_stdtypes | 38 | 143 | `toreadonly`()[¶](#memoryview.toreadonly "Permalink to this definition")
: Return a readonly version of the memoryview object. The original
memoryview object is unchanged.
```None
>>> m = memoryview(bytearray(b'abc'))
>>> mm = m.toreadonly()
>>> mm.tolist()
[89... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
8773a051-909f-52bc-a600-15c2f3b5f0a4 | docs | python | python_stdtypes | 38 | 144 | dangling resources) as soon as possible.
After this method has been called, any further operation on the view
raises a [`ValueError`](exceptions.html#ValueError "ValueError") (except [`release()`](#memoryview.release "memoryview.release") itself which can
be called multiple times):
... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
c5872ca8-2fe6-5633-8584-9ac3d2516548 | docs | python | python_stdtypes | 38 | 145 | `cast`(*format*[, *shape*])[¶](#memoryview.cast "Permalink to this definition")
: Cast a memoryview to a new format or shape. *shape* defaults to
`[byte_length//new_itemsize]`, which means that the result view
will be one-dimensional. The return value is a new memoryview, but
the buffe... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
ac9f5faf-e483-5567-8bfc-a1bc0b977ced | docs | python | python_stdtypes | 38 | 146 | >>> len(x)
3
>>> x.nbytes
24
>>> y = x.cast('B')
>>> y.format
'B'
>>> y.itemsize
1
>>> len(y)
24
>>> y.nbytes
24
```
Cast 1D/unsigned bytes to 1D/char:
```None
>>> b = bytearray(b'zy... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
030d3152-04bb-5891-b30b-274fbf2cc784 | docs | python | python_stdtypes | 38 | 147 | >>> len(y)
2
>>> y.nbytes
48
>>> z = y.cast('b')
>>> z.format
'b'
>>> z.itemsize
1
>>> len(z)
48
>>> z.nbytes
48
```
Cast 1D/unsigned long to 2D/unsigned long:
```None
>>> buf = stru... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
c9630702-e625-506f-9225-781ab0abebb7 | docs | python | python_stdtypes | 38 | 148 | `nbytes`[¶](#memoryview.nbytes "Permalink to this definition")
: `nbytes == product(shape) * itemsize == len(m.tobytes())`. This is
the amount of space in bytes that the array would use in a contiguous
representation. It is not necessarily equal to `len(m)`:
```None
>>> import... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
73bc7711-41b0-5356-a637-3e0c5d9608e6 | docs | python | python_stdtypes | 38 | 149 | `readonly`[¶](#memoryview.readonly "Permalink to this definition")
: A bool indicating whether the memory is read only.
`format`[¶](#memoryview.format "Permalink to this definition")
: A string containing the format (in [`struct`](struct.html#module-struct "struct: Interpret bytes as packed binary ... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
4596030b-d669-54a9-a5cc-ed469908cc7b | docs | python | python_stdtypes | 38 | 150 | >>> m.itemsize
2
>>> m[0]
32000
>>> struct.calcsize('H') == m.itemsize
True
```
`ndim`[¶](#memoryview.ndim "Permalink to this definition")
: An integer indicating how many dimensions of a multi-dimensional array the
memory represents.
`shap... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
3b53c9a8-4645-5f03-ac1a-e1368b9af894 | docs | python | python_stdtypes | 38 | 151 | : Used internally for PIL-style arrays. The value is informational only.
`c_contiguous`[¶](#memoryview.c_contiguous "Permalink to this definition")
: A bool indicating whether the memory is C-[contiguous](../glossary.html#term-contiguous).
New in version 3.3.
`f_contiguous`[¶](#memoryview... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
f308217d-0917-50fd-bfaa-d279171ae259 | docs | python | python_stdtypes | 38 | 152 | 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_38.md |
a3f3ff1b-2d00-5248-bcfa-8146a086b1bb | docs | python | python_stdtypes | 38 | 153 | another set. The [`frozenset`](#frozenset "frozenset") type is immutable and [hashable](../glossary.html#term-hashable) —
its contents cannot be altered after it is created; it can therefore be used as
a dictionary key or as an element of another set.
Non-empty sets (not frozensets) can be created by placing a comma-s... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
ee95c708-f500-58eb-b279-366306aa4d4a | docs | python | python_stdtypes | 38 | 154 | * Use a comma-separated list of elements within braces: `{'jack', 'sjoerd'}`
* Use a set comprehension: `{c for c in 'abracadabra' if c not in 'abc'}`
* Use the type constructor: `set()`, `set('foobar')`, `set(['a', 'b', 'foo'])`
Instances of [`set`](#set "set") and [`frozenset`](#frozenset "frozenset"... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
596671d3-0cab-5332-9c60-b508916873e8 | docs | python | python_stdtypes | 38 | 155 | : Test whether the set is a proper subset of *other*, that is,
`set <= other and set != other`.
`issuperset`(*other*)[¶](#frozenset.issuperset "Permalink to this definition")
`set >= other`
: Test whether every element in *other* is in the set.
`set > other`
: Test whether the s... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
a9160507-fd61-5777-a8fc-3714ade8f6df | docs | python | python_stdtypes | 38 | 156 | `symmetric_difference`(*other*)[¶](#frozenset.symmetric_difference "Permalink to this definition")
`set ^ other`
: Return a new set with elements in either the set or *other* but not both.
`copy`()[¶](#frozenset.copy "Permalink to this definition")
: Return a shallow copy of the set.
Note... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
cb28f8e0-c7d3-58bc-839b-f3ef45dea32a | docs | python | python_stdtypes | 38 | 157 | in favor of the more readable `set('abc').intersection('cbs')`.
Both [`set`](#set "set") and [`frozenset`](#frozenset "frozenset") support set to set comparisons. Two
sets are equal if and only if every element of each set is contained in the
other (each is a subset of the other). A set is less than an... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
a3a71f1b-7bc0-5f82-bd43-78253fc76f68 | docs | python | python_stdtypes | 38 | 158 | subsets of each other, so *all* of the following return `False`: `a<b`,
`a==b`, or `a>b`.
Since sets only define partial ordering (subset relationships), the output of
the [`list.sort()`](#list.sort "list.sort") method is undefined for lists of sets.
Set elements, like dictionary keys, must be [ha... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
b7120a51-a01b-5108-aa96-6108810207e4 | docs | python | python_stdtypes | 38 | 159 | `intersection_update`(*\*others*)[¶](#frozenset.intersection_update "Permalink to this definition")
`set &= other & ...`
: Update the set, keeping only elements found in it and all others.
`difference_update`(*\*others*)[¶](#frozenset.difference_update "Permalink to this definition")
`set -= ot... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
5ec04cc4-24ac-58f8-b34d-8aa7fbbbf32b | docs | python | python_stdtypes | 38 | 160 | : Remove element *elem* from the set if it is present.
`pop`()[¶](#frozenset.pop "Permalink to this definition")
: Remove and return an arbitrary element from the set. Raises
[`KeyError`](exceptions.html#KeyError "KeyError") if the set is empty.
`clear`()[¶](#frozenset.clear "Permalink to ... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
3cbff18b-efa5-532e-a1b6-a195115a6ff4 | docs | python | python_stdtypes | 38 | 161 | [`discard()`](#frozenset.discard "frozenset.discard") methods may be a set. To support searching for an equivalent
frozenset, a temporary one is created from *elem*.
## Mapping Types — [`dict`](#dict "dict")[¶](#mapping-types-dict "Permalink to this headline")
A [mapping](../glossary.html#term-mapping) object... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
44c0aa72-f6c7-59e3-b851-e59038677cce | docs | python | python_stdtypes | 38 | 162 | not be used as keys. Numeric types used for keys obey the normal rules for
numeric comparison: if two numbers compare equal (such as `1` and `1.0`)
then they can be used interchangeably to index the same dictionary entry. (Note
however, that since computers store floating-point numbers as approximations it
is usually u... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
d10b66ba-acf5-5808-bef7-b6df898e70aa | docs | python | python_stdtypes | 38 | 163 | `{'jack': 4098, 'sjoerd': 4127}` or `{4098: 'jack', 4127: 'sjoerd'}`
* Use a dict comprehension: `{}`, `{x: x ** 2 for x in range(10)}`
* Use the type constructor: `dict()`,
`dict([('foo', 100), ('bar', 200)])`, `dict(foo=100, bar=200)`
If no positional argument is given, an empty dictionary is... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
28f70511-07fc-5077-9d85-26068859c3d2 | docs | python | python_stdtypes | 38 | 164 | added to the dictionary created from the positional argument. If a key
being added is already present, the value from the keyword argument
replaces the value from the positional argument.
To illustrate, the following examples all return a dictionary equal to
`{"one": 1, "two": 2, "three": 3}`:
... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
52d0a774-27a1-518c-85d2-ec1775a3beb5 | docs | python | python_stdtypes | 38 | 165 | : Return the number of items in the dictionary *d*.
`d[key]`
: Return the item of *d* with key *key*. Raises a [`KeyError`](exceptions.html#KeyError "KeyError") if *key* is
not in the map.
If a subclass of dict defines a method [`__missing__()`](../reference/datamodel.html#object.__mis... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
2cdc6c75-6ba4-51d1-8012-7db9225450e4 | docs | python | python_stdtypes | 38 | 166 | [`__missing__()`](../reference/datamodel.html#object.__missing__ "object.__missing__") must be a method; it cannot be an instance variable:
```None
>>> class Counter(dict):
... def __missing__(self, key):
... return 0
>>> c = Counter()
>>> c['red']
... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
dcdb5dcc-7285-5375-b1fa-8e9c20631472 | docs | python | python_stdtypes | 38 | 167 | : Equivalent to `not key in d`.
`iter(d)`
: Return an iterator over the keys of the dictionary. This is a shortcut
for `iter(d.keys())`.
`clear`()[¶](#dict.clear "Permalink to this definition")
: Remove all items from the dictionary.
`copy`()[¶](#dict.copy "Permalink to this def... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
374f60ca-405a-58ab-9f05-09144fc92714 | docs | python | python_stdtypes | 38 | 168 | `get`(*key*[, *default*])[¶](#dict.get "Permalink to this definition")
: Return the value for *key* if *key* is in the dictionary, else *default*.
If *default* is not given, it defaults to `None`, so that this method
never raises a [`KeyError`](exceptions.html#KeyError "KeyError").
`items... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
61db455a-5387-5d65-a514-98773512f5ed | docs | python | python_stdtypes | 38 | 169 | `popitem`()[¶](#dict.popitem "Permalink to this definition")
: Remove and return a `(key, value)` pair from the dictionary.
Pairs are returned in LIFO order.
[`popitem()`](#dict.popitem "dict.popitem") is useful to destructively iterate over a dictionary, as
often used in set algorith... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
f1c32f72-655e-524c-a45f-7b6a4f6ba4ce | docs | python | python_stdtypes | 38 | 170 | with a value of *default* and return *default*. *default* defaults to
`None`.
`update`([*other*])[¶](#dict.update "Permalink to this definition")
: Update the dictionary with the key/value pairs from *other*, overwriting
existing keys. Return `None`.
[`update()`](#dict.update... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
53db32b5-a19f-52f1-9faa-f39ae833070c | docs | python | python_stdtypes | 38 | 171 | >>> d.values() == d.values()
False
```
Dictionaries compare equal if and only if they have the same `(key,
value)` pairs (regardless of ordering). Order comparisons (‘<’, ‘<=’, ‘>=’, ‘>’) raise
[`TypeError`](exceptions.html#TypeError "TypeError").
Dictionaries preserve insertio... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
f78a95a7-7dae-56e5-9693-7e421e20774b | docs | python | python_stdtypes | 38 | 172 | Dictionaries and dictionary views are reversible.
```None
>>> d = {"one": 1, "two": 2, "three": 3, "four": 4}
>>> d
{'one': 1, 'two': 2, 'three': 3, 'four': 4}
>>> list(reversed(d))
['four', 'three', 'two', 'one']
>>> list(reversed(d.values()))
[4, 3, 2, 1]
>>> list(reversed(d.i... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
0c3f9404-ac16-5a81-8b2c-aa506a6db97f | docs | python | python_stdtypes | 38 | 173 | Dictionary views can be iterated over to yield their respective data, and
support membership tests:
`len(dictview)`
: Return the number of entries in the dictionary.
`iter(dictview)`
: Return an iterator over the keys, values or items (represented as tuples of
`(key, value)`) in the dictionary.
Keys and ... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
71c57f3a-f0c5-5535-bb5b-4cc29cf95d32 | docs | python | python_stdtypes | 38 | 174 | `reversed(dictview)`
: Return a reverse iterator over the keys, values or items of the dictionary.
The view will be iterated in reverse order of the insertion.
Changed in version 3.8: Dictionary views are now reversible.
Keys views are set-like since their entries are unique and hashable. If all
values are ... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
26829259-af12-5e42-bac9-e5c4025d1715 | docs | python | python_stdtypes | 38 | 175 | >>> # keys and values are iterated over in the same order (insertion order)
>>> list(keys)
['eggs', 'sausage', 'bacon', 'spam']
>>> list(values)
[2, 1, 1, 500]
>>> # view objects are dynamic and reflect dict changes
>>> del dishes['eggs']
>>> del dishes['sausage']
>>> list(keys)
['bacon', 'spam']
>>> # set operations... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
451d8eea-74f5-5001-9a5b-5d06bd88323f | docs | python | python_stdtypes | 38 | 176 | : Enter the runtime context and return either this object or another object
related to the runtime context. The value returned by this method is bound to
the identifier in the `as` clause of [`with`](../reference/compound_stmts.html#with) statements using
this context manager.
An example of a context... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
7bebfe1e-6aca-5351-b932-c8d1e48c960a | docs | python | python_stdtypes | 38 | 177 | of the [`with`](../reference/compound_stmts.html#with) statement without affecting code outside the
`with` statement.
`contextmanager.``__exit__`(*exc\_type*, *exc\_val*, *exc\_tb*)[¶](#contextmanager.__exit__ "Permalink to this definition")
: Exit the runtime context and return a Boolean flag indicating if ... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
40f51ced-db51-57a3-81a1-7bc084800af7 | docs | python | python_stdtypes | 38 | 178 | during execution of this method will replace any exception that occurred in the
body of the `with` statement.
The exception passed in should never be reraised explicitly - instead, this
method should return a false value to indicate that the method completed
successfully and does not want to suppre... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
0985a2df-0ceb-5f96-86e0-a064eb519af3 | docs | python | python_stdtypes | 38 | 179 | Python’s [generator](../glossary.html#term-generator)s and the [`contextlib.contextmanager`](contextlib.html#contextlib.contextmanager "contextlib.contextmanager") decorator
provide a convenient way to implement these protocols. If a generator function is
decorated with the [`contextlib.contextmanager`](contextlib.html... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
dadcf048-5ce2-5823-8170-ab52ec71bcfa | docs | python | python_stdtypes | 38 | 180 | single class dictionary lookup is negligible.
## Other Built-in Types[¶](#other-built-in-types "Permalink to this headline")
The interpreter supports several other kinds of objects. Most of these support
only one or two operations.
### Modules[¶](#modules "Permalink to this headline")
The only special operation on ... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
a3b54f35-8cac-5bdc-a1b3-0ce1622773b4 | docs | python | python_stdtypes | 38 | 181 | [`__dict__`](#object.__dict__ "object.__dict__") attribute is not possible (you can write
`m.__dict__['a'] = 1`, which defines `m.a` to be `1`, but you can’t write
`m.__dict__ = {}`). Modifying [`__dict__`](#object.__dict__ "object.__dict__") directly is
not recommended.
Modules built into the interpreter are written ... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
4b9669f4-8a65-5d82-8dd8-85bfdf973471 | docs | python | python_stdtypes | 38 | 182 | user-defined functions. Both support the same operation (to call the function),
but the implementation is different, hence the different object types.
See [Function definitions](../reference/compound_stmts.html#function) for more information.
### Methods[¶](#methods "Permalink to this headline")
Methods are function... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
027e77ff-2682-5ddf-930e-6ff532560b99 | docs | python | python_stdtypes | 38 | 183 | is completely equivalent to calling `m.__func__(m.__self__, arg-1, arg-2, ...,
arg-n)`.
Like function objects, bound method objects support getting arbitrary
attributes. However, since method attributes are actually stored on the
underlying function object (`meth.__func__`), setting method attributes on
bound methods ... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
9837ab89-29a4-5f3b-9737-e155080eb703 | docs | python | python_stdtypes | 38 | 184 | See [The standard type hierarchy](../reference/datamodel.html#types) for more information.
### Code Objects[¶](#code-objects "Permalink to this headline")
Code objects are used by the implementation to represent “pseudo-compiled”
executable Python code such as a function body. They differ from function
objects becaus... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
9cf293c9-a539-533b-a75a-e62b77e564a7 | docs | python | python_stdtypes | 38 | 185 | See [The standard type hierarchy](../reference/datamodel.html#types) for more information.
### Type Objects[¶](#type-objects "Permalink to this headline")
Type objects represent the various object types. An object’s type is accessed
by the built-in function [`type()`](functions.html#type "type"). There are no special... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
931e8705-ca72-5aa4-867a-a01a4ecf9493 | docs | python | python_stdtypes | 38 | 186 | ### The Ellipsis Object[¶](#the-ellipsis-object "Permalink to this headline")
This object is commonly used by slicing (see [Slicings](../reference/expressions.html#slicings)). It supports no
special operations. There is exactly one ellipsis object, named
[`Ellipsis`](constants.html#Ellipsis "Ellipsis") (a built-in nam... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
f62f1379-a049-590d-a68d-0aa3c04b40a4 | docs | python | python_stdtypes | 38 | 187 | ### Boolean Values[¶](#boolean-values "Permalink to this headline")
Boolean values are the two constant objects `False` and `True`. They are
used to represent truth values (although other values can also be considered
false or true). In numeric contexts (for example when used as the argument to
an arithmetic operator)... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
1655055e-c206-51e6-8489-0d2081d89611 | docs | python | python_stdtypes | 38 | 188 | ## Special Attributes[¶](#special-attributes "Permalink to this headline")
The implementation adds a few special read-only attributes to several object
types, where they are relevant. Some of these are not reported by the
[`dir()`](functions.html#dir "dir") built-in function.
`object.``__dict__`[¶](#object.__dict__ "... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
9840dc5d-e868-5f3c-bf58-9499bfe35aa8 | docs | python | python_stdtypes | 38 | 189 | : The [qualified name](../glossary.html#term-qualified-name) of the class, function, method, descriptor,
or generator instance.
New in version 3.3.
`class.``__mro__`[¶](#class.__mro__ "Permalink to this definition")
: This attribute is a tuple of classes that are considered when looking for
base class... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
13ab9dd6-7dfa-54bb-b2dd-c50812037ef8 | docs | python | python_stdtypes | 38 | 190 | ## Integer string conversion length limitation[¶](#integer-string-conversion-length-limitation "Permalink to this headline")
CPython has a global limit for converting between [`int`](functions.html#int "int") and [`str`](#str "str")
to mitigate denial of service attacks. This limit *only* applies to decimal or
other n... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
f8ac493e-27f7-5dcb-806b-96f046296515 | docs | python | python_stdtypes | 38 | 191 | Limiting conversion size offers a practical way to avoid [CVE-2020-10735](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-10735).
The limit is applied to the number of digit characters in the input or output
string when a non-linear conversion algorithm would be involved. Underscores
and the sign are not count... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
39ab2c19-9048-50b9-9a24-8a2e1e6e3e18 | docs | python | python_stdtypes | 38 | 192 | ValueError: Exceeds the limit (4300) for integer string conversion: value has 8599 digits; use sys.set_int_max_str_digits() to increase the limit.
>>> len(hex(i_squared))
7144
>>> assert int(hex(i_squared), base=16) == i*i # Hexadecimal is unlimited.
```
The default limit is 4300 digits as provided in
[`sys.int_info.... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
c580a0ee-214c-5e46-aba4-e316555b94b2 | docs | python | python_stdtypes | 38 | 193 | ### Affected APIs[¶](#affected-apis "Permalink to this headline")
The limitation only applies to potentially slow conversions between [`int`](functions.html#int "int")
and [`str`](#str "str") or [`bytes`](#bytes "bytes"):
* `int(string)` with default base 10.
* `int(string, base)` for all bases that are not a power o... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
f44bc2a9-8cc3-51fe-a117-6ff249f4edb1 | docs | python | python_stdtypes | 38 | 194 | * [`str`](#str "str") to [`decimal.Decimal`](decimal.html#decimal.Decimal "decimal.Decimal").
### Configuring the limit[¶](#configuring-the-limit "Permalink to this headline")
Before Python starts up you can use an environment variable or an interpreter
command line flag to configure the limit:
* [`PYTHONINTMAXSTRDI... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
7ff1c30c-c39c-5863-bdfa-1a509753ca00 | docs | python | python_stdtypes | 38 | 195 | `sys.int_info.default_max_str_digits` was used during initialization.
From code, you can inspect the current limit and set a new one using these
[`sys`](sys.html#module-sys "sys: Access system-specific parameters and functions.") APIs:
* [`sys.get_int_max_str_digits()`](sys.html#sys.get_int_max_str_digits "sys.get_... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
a2e6632b-8d19-54aa-927e-294e436033df | docs | python | python_stdtypes | 38 | 196 | Setting a low limit *can* lead to problems. While rare, code exists that
contains integer constants in decimal in their source that exceed the
minimum threshold. A consequence of setting the limit is that Python source
code containing decimal integer literals longer than the limit will
encounter an error during parsing... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
81d42a68-fcf4-5adb-aa29-793d59b8526f | docs | python | python_stdtypes | 38 | 197 | ### Recommended configuration[¶](#recommended-configuration "Permalink to this headline")
The default `sys.int_info.default_max_str_digits` is expected to be
reasonable for most applications. If your application requires a different
limit, set it from your main entry point using Python version agnostic code as
these A... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
fa578910-9787-50f8-b6c5-55544e37f24d | docs | python | python_stdtypes | 38 | 198 | Reference Manual ([Basic customization](../reference/datamodel.html#customization)).
[2](#id2)
: As a consequence, the list `[1, 2]` is considered equal to `[1.0, 2.0]`, and
similarly for tuples.
[3](#id4)
: They must have since the parser can’t tell the type of the operands.
4([1](#id6),[2](#id7),[3](#i... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
0e730322-336e-54ff-947f-5330f74e3aab | docs | python | python_stdtypes | 39 | 0 | # Built-in Types¶
Source: https://docs.python.org/3.9/library/stdtypes.html
Version: 3.9
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. The... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
f0ac0e8e-f35e-5d3f-8d50-e19f6ea134f9 | docs | python | python_stdtypes | 39 | 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_39.md |
b92dc46c-cb7e-549f-903f-5f46ced0e945 | docs | python | python_stdtypes | 39 | 2 | or `False` for false and `1` or `True` for true, unless otherwise stated.
(Important exception: the Boolean operations `or` and `and` always return
one of their operands.)
## Boolean Operations — `and`, `or`, `not`[¶](#boolean-operations-and-or-not "Permalink to this headline")
These are the Boolean operations, order... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
6b08c0fd-151c-5722-a0f1-956b0d07e333 | docs | python | python_stdtypes | 39 | 3 | ## Comparisons[¶](#comparisons "Permalink to this headline")
There are eight comparison operations in Python. They all have the same
priority (which is higher than that of the Boolean operations). Comparisons can
be chained arbitrarily; for example, `x < y <= z` is equivalent to `x < y and
y <= z`, except that *y* is ... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
7fd4a748-11ac-5ff2-a017-8388de41d16e | docs | python | python_stdtypes | 39 | 4 | operators are only defined where they make sense; for example, they raise a
[`TypeError`](exceptions.html#TypeError "TypeError") exception when one of the arguments is a complex number.
Non-identical instances of a class normally compare as non-equal unless the
class defines the [`__eq__()`](../reference/datamodel.htm... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
e4850d68-c7a8-5186-8f34-b99d62c20c90 | docs | python | python_stdtypes | 39 | 5 | [`__eq__()`](../reference/datamodel.html#object.__eq__ "object.__eq__") are sufficient, if you want the conventional meanings of the
comparison operators).
The behavior of the [`is`](../reference/expressions.html#is) and [`is not`](../reference/expressions.html#is-not) operators cannot be
customized; also they can be ... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
1b44d888-f686-5d96-9daf-e473e2161b5e | docs | python | python_stdtypes | 39 | 6 | point numbers*, and *complex numbers*. In addition, Booleans are a
subtype of integers. Integers have unlimited precision. Floating point
numbers are usually implemented using `double` in C; information
about the precision and internal representation of floating point
numbers for the machine on which your program is ru... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
881ba7fa-ed99-5856-8bdf-d5122faee293 | docs | python | python_stdtypes | 39 | 7 | numbers) yield integers. Numeric literals containing a decimal point or an
exponent sign yield floating point numbers. Appending `'j'` or `'J'` to a
numeric literal yields an imaginary number (a complex number with a zero real
part) which you can add to an integer or float to get a complex number with real
and imaginar... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
1df78e94-07ca-538a-8e02-48d7640e84e0 | docs | python | python_stdtypes | 39 | 8 | the operations, see [Operator precedence](../reference/expressions.html#operator-summary)):
| Operation | Result | Notes | Full documentation |
| --- | --- | --- | --- |
| `x + y` | sum of *x* and *y* | | |
| `x - y` | difference of *x* and *y* | | |
| `x * y` | product of *x* and *y* | | |
| `x / y` | quotient ... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
a3fa3022-5609-5230-85ee-5f1d7423b851 | docs | python | python_stdtypes | 39 | 9 | | `divmod(x, y)` | the pair `(x // y, x % y)` | (2) | [`divmod()`](functions.html#divmod "divmod") |
| `pow(x, y)` | *x* to the power *y* | (5) | [`pow()`](functions.html#pow "pow") |
| `x ** y` | *x* to the power *y* | (5) | |
Notes:
1. Also referred to as integer division. The resultant value is a whole
integer... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
e451d841-4ef4-5d10-9ead-8888bfbf98d9 | docs | python | python_stdtypes | 39 | 10 | 5. Python defines `pow(0, 0)` and `0 ** 0` to be `1`, as is common for
programming languages.
6. The numeric literals accepted include the digits `0` to `9` or any
Unicode equivalent (code points with the `Nd` property).
See <https://www.unicode.org/Public/13.0.0/ucd/extracted/DerivedNumericType.txt>
for a... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
5bacc2e7-4eca-5cea-8973-6b2c8ed28616 | docs | python | python_stdtypes | 39 | 11 | | [`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_39.md |
90b94a0d-2fc1-5fb8-8f5f-67e851263a33 | docs | python | python_stdtypes | 39 | 12 | | `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_39.md |
6d882d2c-5ee1-5410-bf85-3e990b7fc04a | docs | python | python_stdtypes | 39 | 13 | ### Additional Methods on Integer Types[¶](#additional-methods-on-integer-types "Permalink to this headline")
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:... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
34099230-326f-59db-b028-0427d794fab7 | docs | python | python_stdtypes | 39 | 14 | s = bin(self) # binary representation: bin(-37) --> '-0b100101'
s = s.lstrip('-0b') # remove leading zeros and minus sign
return len(s) # len('100101') --> 6
```
New in version 3.1.
`int.``to_bytes`(*length*, *byteorder*, *\**, *signed=False*)[¶](#int.to_bytes "Permalink t... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
7dd8f785-0570-5279-83b8-7b1ad95817e5 | docs | python | python_stdtypes | 39 | 15 | The *byteorder* argument determines the byte order used to represent the
integer. If *byteorder* is `"big"`, the most significant byte is at the
beginning of the byte array. If *byteorder* is `"little"`, the most
significant byte is at the end of the byte array. To request the native
byte order of t... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
c178a55a-6077-5e80-81bf-c834742a0d9e | docs | python | python_stdtypes | 39 | 16 | >>> int.from_bytes(b'\x00\x10', byteorder='little')
4096
>>> int.from_bytes(b'\xfc\x00', byteorder='big', signed=True)
-1024
>>> int.from_bytes(b'\xfc\x00', byteorder='big', signed=False)
64512
>>> int.from_bytes([255, 0, 0], byteorder='big')
16711680
```
The argument *bytes* mu... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
322175af-724c-56e3-a82f-a1fe2243bdd4 | docs | python | python_stdtypes | 39 | 17 | `int.``as_integer_ratio`()[¶](#int.as_integer_ratio "Permalink to this definition")
: Return a pair of integers whose ratio is exactly equal to the original
integer and with a positive denominator. The integer ratio of integers
(whole numbers) is always the integer as the numerator and `1` as the
denomina... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
26be1060-39fe-5410-99ff-cec612641b0d | docs | python | python_stdtypes | 39 | 18 | `float.``is_integer`()[¶](#float.is_integer "Permalink 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 hexadec... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
3376a90a-b40c-5085-af9b-37a0481342a3 | docs | python | python_stdtypes | 39 | 19 | : 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_39.md |
288036e2-b9a3-5f34-a393-d6f46c93de08 | docs | python | python_stdtypes | 39 | 20 | 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_39.md |
664a05d4-e676-58ee-aac5-a7dc486c6805 | docs | python | python_stdtypes | 39 | 21 | efficiency across a variety of numeric types (including [`int`](functions.html#int "int"),
[`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 b... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
8c098722-f118-50ba-9e6a-c8652eec17c7 | docs | python | python_stdtypes | 39 | 22 | 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_39.md |
5fa05f36-aa5f-501c-9bb2-f3a94671f3e6 | docs | python | python_stdtypes | 39 | 23 | and imaginary parts are combined by computing `hash(z.real) +
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,... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
be1fda14-2ad8-5a92-9778-20210f2935f6 | docs | python | python_stdtypes | 39 | 24 | # Fermat's Little Theorem: pow(n, P-1, P) is 1, so
# 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):
"""C... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
9b8864ad-bba2-5cd3-ab3a-3a6266074de7 | docs | python | python_stdtypes | 39 | 25 | ## Iterator Types[¶](#iterator-types "Permalink to this headline")
Python supports a concept of iteration over containers. This is implemented
using two distinct methods; these are used to allow user-defined classes to
support iteration. Sequences, described below in more detail, always support
the iteration methods.
... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
47e1079b-1680-5805-8dfd-beecb515fe90 | docs | python | python_stdtypes | 39 | 26 | [`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.
The iterator objects themselves are required to support the following two
methods, which together form the *iterator protocol*:
`iterator.``__iter__`()[¶](#iterat... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
051c91b0-47be-50a9-863c-0392742dd71c | docs | python | python_stdtypes | 39 | 27 | the [`StopIteration`](exceptions.html#StopIteration "StopIteration") exception. This method corresponds to the
[`tp_iternext`](../c-api/typeobj.html#c.PyTypeObject.tp_iternext "PyTypeObject.tp_iternext") slot of the type structure for Python objects in the
Python/C API.
Python defines several iterator obje... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
98b18857-fa1d-55d1-abab-b9cb10631ec4 | docs | python | python_stdtypes | 39 | 28 | protocol. If a container object’s [`__iter__()`](../reference/datamodel.html#object.__iter__ "object.__iter__") method is implemented as a
generator, it will automatically return an iterator object (technically, a
generator object) supplying the [`__iter__()`](../reference/datamodel.html#object.__iter__ "object.__iter_... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
c819f766-2607-5c48-a638-b3625fdddf1a | docs | python | python_stdtypes | 39 | 29 | ### Common Sequence Operations[¶](#common-sequence-operations "Permalink to this headline")
The operations in the following table are supported by most sequence types,
both mutable and immutable. The [`collections.abc.Sequence`](collections.abc.html#collections.abc.Sequence "collections.abc.Sequence") ABC is
provided ... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
318cc82d-5d41-5e65-b265-1681fb03f5ec | docs | python | python_stdtypes | 39 | 30 | | `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 itself *n* times | (2)(7) |
| `s[i]` | *i*th item of *s*, origin 0 | (3) |
| `s[i:j]` | slice of *s* from *i* to *j* | (3)(4) |
| `s[... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
f18450ea-db91-5fbb-aa68-e3fbd60c29d6 | docs | python | python_stdtypes | 39 | 31 | details see [Comparisons](../reference/expressions.html#comparisons) in the language reference.)
Notes:
1. While the `in` and `not in` operations are used only for simple
containment testing in the general case, some specialised sequences
(such as [`str`](#str "str"), [`bytes`](#bytes "bytes") and [`bytearray`]... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
eb4c50e6-7b7e-5295-b000-16a8723f383a | docs | python | python_stdtypes | 39 | 32 | list. Modifying any of the elements of `lists` modifies this single list.
You can create a list of different lists this way:
```None
>>> lists = [[] for i in range(3)]
>>> lists[0].append(3)
>>> lists[1].append(5)
>>> lists[2].append(7)
>>> lists
[[3], [5], [7]]
```
Further explanatio... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
5dacaed7-84ef-58e7-aa9f-fa92b2ec8ee4 | docs | python | python_stdtypes | 39 | 33 | items with index `x = i + n*k` such that `0 <= n < (j-i)/k`. In other words,
the indices are `i`, `i+k`, `i+2*k`, `i+3*k` and so on, stopping when
*j* is reached (but never including *j*). When *k* is positive,
*i* and *j* are reduced to `len(s)` if they are greater.
When *k* is negative, *i* and *j* are... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
fa0920c1-2574-5416-a921-1564c3a2c43e | docs | python | python_stdtypes | 39 | 34 | [`str.join()`](#str.join "str.join") at the end or else write to an [`io.StringIO`](io.html#io.StringIO "io.StringIO")
instance and retrieve its value when complete
* if concatenating [`bytes`](#bytes "bytes") objects, you can similarly use
[`bytes.join()`](#bytes.join "bytes.join") or [`io.BytesIO`](... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
53f53385-d750-5215-b600-8222b4dbb40d | docs | python | python_stdtypes | 39 | 35 | Not all implementations support passing the additional arguments *i* and *j*.
These arguments allow efficient searching of subsections of the sequence. Passing
the extra arguments is roughly equivalent to using `s[i:j].index(x)`, only
without copying any data and with the returned index being relative to
... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
f35375c3-1b6a-5abc-a152-e78220e8e932 | docs | python | python_stdtypes | 39 | 36 | ### Mutable Sequence Types[¶](#mutable-sequence-types "Permalink to this headline")
The operations in the following table are defined on mutable sequence types.
The [`collections.abc.MutableSequence`](collections.abc.html#collections.abc.MutableSequence "collections.abc.MutableSequence") ABC is provided to make it
eas... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
371f9104-f599-5213-b4ef-e590d7799904 | docs | python | python_stdtypes | 39 | 37 | | `del s[i:j:k]` | removes the elements of `s[i:j:k]` from the list | |
| `s.append(x)` | appends *x* to the end of the sequence (same as `s[len(s):len(s)] = [x]`) | |
| `s.clear()` | removes all items from *s* (same as `del s[:]`) | (5) |
| `s.copy()` | creates a shallow copy of *s* (same as `s[:]`) | (5) |
| `s.ext... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
39102a3f-b612-5ace-b5fe-3a176c452814 | docs | python | python_stdtypes | 39 | 38 | 3. `remove()` raises [`ValueError`](exceptions.html#ValueError "ValueError") when *x* is not found in *s*.
4. The `reverse()` method modifies the sequence in place for economy of
space when reversing a large sequence. To remind users that it operates by
side effect, it does not return the reversed sequence.
5. `c... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
0dabb94e-0ebc-5949-b72f-20509a8be6f4 | docs | python | python_stdtypes | 39 | 39 | the sequence. Items in the sequence are not copied; they are referenced
multiple times, as explained for `s * n` under [Common Sequence Operations](#typesseq-common).
### Lists[¶](#lists "Permalink to this headline")
Lists are mutable sequences, typically used to store collections of
homogeneous items (where th... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
9745fc5c-aebf-58e1-92e0-877a06ce737f | docs | python | python_stdtypes | 39 | 40 | is already a list, a copy is made and returned, similar to `iterable[:]`.
For example, `list('abc')` returns `['a', 'b', 'c']` and
`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 th... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.