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 |
|---|---|---|---|---|---|---|---|
c44bc55d-845a-51c7-a6a1-355884c63cd1 | docs | python | python_stdtypes | 38 | 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_38.md |
2abbd2a1-9bad-595d-b906-fc5e5df21dbc | docs | python | python_stdtypes | 38 | 41 | [`sort()`](#list.sort "list.sort") accepts two arguments that can only be passed by keyword
([keyword-only arguments](../glossary.html#keyword-only-parameter)):
*key* specifies a function of one argument that is used to extract a
comparison key from each list element (for example, `key=... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
e63f3b52-eea2-5acf-9806-89a7d7077d3e | docs | python | python_stdtypes | 38 | 42 | sorting a large sequence. To remind users that it operates by side
effect, it does not return the sorted sequence (use [`sorted()`](functions.html#sorted "sorted") to
explicitly request a new sorted list instance).
The [`sort()`](#list.sort "list.sort") method is guaranteed to be stable... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
e5801c2e-3c73-5cda-baa1-82be32d0e90e | docs | python | python_stdtypes | 38 | 43 | detect that the list has been mutated during a sort.
### 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 a... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
32ae75c9-958c-5531-83c2-6bd556786bcb | docs | python | python_stdtypes | 38 | 44 | order as *iterable*’s items. *iterable* may be either a sequence, a
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 argu... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
72c89bc6-8063-5bc9-abb1-9c6953f45ab5 | docs | python | python_stdtypes | 38 | 45 | access by index, [`collections.namedtuple()`](collections.html#collections.namedtuple "collections.namedtuple") may be a more appropriate
choice than a simple tuple object.
### Ranges[¶](#ranges "Permalink to this headline")
The [`range`](#range "range") type represents an immutable sequence of numbers and is
commonl... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
25bbd22c-4676-5ccd-8d54-aaa7e14ef5f2 | docs | python | python_stdtypes | 38 | 46 | formula `r[i] = start + step*i` where `i >= 0` and
`r[i] < stop`.
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
... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
66239e85-6242-590b-b810-b6f79805a07b | docs | python | python_stdtypes | 38 | 47 | >>> list(range(0, -10, -1))
[0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
>>> 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 repr... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
cc1fca68-6348-5f72-beb0-5ddee0bfb879 | docs | python | python_stdtypes | 38 | 48 | [`tuple`](#tuple "tuple") is that a [`range`](#range "range") object will always take the same
(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 [`collectio... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
3bcf1c7f-8958-5960-be0a-f8e7b164f960 | docs | python | python_stdtypes | 38 | 49 | objects that compare equal might have different [`start`](#range.start "range.start"),
[`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 slici... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
9aea7dfc-f74b-558f-9618-d614ae1087e5 | docs | python | python_stdtypes | 38 | 50 | ## 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_38.md |
163a015d-ccc5-573f-8e4f-f466585c818a | docs | python | python_stdtypes | 38 | 51 | 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_38.md |
2cddcaa9-f17e-5dcc-a3d3-e328938faedb | docs | python | python_stdtypes | 38 | 52 | depends on whether *encoding* or *errors* is given, as follows.
If neither *encoding* nor *errors* is given, `str(object)` returns
[`object.__str__()`](../reference/datamodel.html#object.__str__ "object.__str__"), which is the “informal” or nicely
printable string representation of *object*. For string... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
a51fd710-bb32-5b15-9452-8217b8adca06 | docs | python | python_stdtypes | 38 | 53 | [`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_38.md |
3b446bb4-6756-5426-929a-354cfd3c5b7f | docs | python | python_stdtypes | 38 | 54 | 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_38.md |
793a659b-822f-5a23-b670-556595ba1937 | docs | python | python_stdtypes | 38 | 55 | 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_38.md |
8abd7f22-a7fc-522f-8ef4-8c24cd48d026 | docs | python | python_stdtypes | 38 | 56 | 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_38.md |
62da22e1-d13d-5857-9509-6fb2ce6ab2e4 | docs | python | python_stdtypes | 38 | 57 | : Return an encoded version of the string as a bytes object. Default encoding
is `'utf-8'`. *errors* may be given to set a different error handling scheme.
The default for *errors* is `'strict'`, meaning that encoding errors raise
a [`UnicodeError`](exceptions.html#UnicodeError "UnicodeError"). Other poss... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
b7703364-5de8-52eb-8141-e2e3de44ec1a | docs | python | python_stdtypes | 38 | 58 | `False`. *suffix* can also be a tuple of suffixes to look for. With optional
*start*, test beginning at that position. With optional *end*, stop comparing
at that position.
`str.``expandtabs`(*tabsize=8*)[¶](#str.expandtabs "Permalink to this definition")
: Return a copy of the string where all tab chara... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
08b20f5c-89f3-5afc-9d10-1223cb467b67 | docs | python | python_stdtypes | 38 | 59 | zero. Any other character is copied unchanged and the current column is
incremented by one regardless of how the character is represented when
printed.
```None
>>> '01\t012\t0123\t01234'.expandtabs()
'01 012 0123 01234'
>>> '01\t012\t0123\t01234'.expandtabs(4)
'01 012 0123 ... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
c5341e40-2dbd-5429-aa26-1b2c0ff8283d | docs | python | python_stdtypes | 38 | 60 | : Perform a string formatting operation. The string on which this method is
called can contain literal text or replacement fields delimited by braces
`{}`. Each replacement field contains either the numeric index of a
positional argument, or the name of a keyword argument. Returns a copy of
the string... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
c6c61f80-f96a-5c68-942c-82b3e9ac8649 | docs | python | python_stdtypes | 38 | 61 | `LC_CTYPE` locale to the `LC_NUMERIC` locale to decode
`decimal_point` and `thousands_sep` fields of `localeconv()` if
they are non-ASCII or longer than 1 byte, and the `LC_NUMERIC` locale is
different than the `LC_CTYPE` locale. This temporary change affects
other threads.
Changed in version 3... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
8cb81880-5712-5082-a2ee-fb1375d2f8ba | docs | python | python_stdtypes | 38 | 62 | `str.``index`(*sub*[, *start*[, *end*]])[¶](#str.index "Permalink to this definition")
: Like [`find()`](#str.find "str.find"), but raise [`ValueError`](exceptions.html#ValueError "ValueError") when the substring is
not found.
`str.``isalnum`()[¶](#str.isalnum "Permalink to this definition")
: Return `True` if... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
86026874-4d78-5881-b634-0f91230fc86c | docs | python | python_stdtypes | 38 | 63 | from the “Alphabetic” property defined in the Unicode Standard.
`str.``isascii`()[¶](#str.isascii "Permalink to this definition")
: Return `True` if the string is empty or all characters in the string are ASCII,
`False` otherwise.
ASCII characters have code points in the range U+0000-U+007F.
New in ... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
14cb336c-794f-5f75-aa0e-4d3bf003da90 | docs | python | python_stdtypes | 38 | 64 | special handling, such as the compatibility superscript digits.
This covers digits which cannot be used to form numbers in base 10,
like the Kharosthi numbers. Formally, a digit is a character that has the
property value Numeric\_Type=Digit or Numeric\_Type=Decimal.
`str.``isidentifier`()[¶](#str.iside... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
b36a696a-3b3a-5e31-b145-3b34beb6e14f | docs | python | python_stdtypes | 38 | 65 | `str.``islower`()[¶](#str.islower "Permalink to this definition")
: Return `True` if all cased characters [4](#id15) in the string are lowercase and
there is at least one cased character, `False` otherwise.
`str.``isnumeric`()[¶](#str.isnumeric "Permalink to this definition")
: Return `True` if all characters ... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
d9aa1047-b6af-56bb-822e-80ff1c0ad9b3 | docs | python | python_stdtypes | 38 | 66 | in the Unicode character database as “Other” or “Separator”, excepting the
ASCII space (0x20) which is considered printable. (Note that printable
characters in this context are those which should not be escaped when
[`repr()`](functions.html#repr "repr") is invoked on a string. It has no bearing on the ... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
849381b5-cdc4-53fe-a113-3e336c3a7f23 | docs | python | python_stdtypes | 38 | 67 | : Return `True` if the string is a titlecased string and there is at least one
character, for example uppercase characters may only follow uncased characters
and lowercase characters only cased ones. Return `False` otherwise.
`str.``isupper`()[¶](#str.isupper "Permalink to this definition")
: Return `True`... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
2262c369-8301-534a-892d-3cb747008b7e | docs | python | python_stdtypes | 38 | 68 | done using the specified *fillchar* (default is an ASCII space). The
original string is returned if *width* is less than or equal to `len(s)`.
`str.``lower`()[¶](#str.lower "Permalink to this definition")
: Return a copy of the string with all the cased characters [4](#id15) converted to
lowercase.
... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
dfcd13cf-45e8-5ab9-9602-ceffe0559252 | docs | python | python_stdtypes | 38 | 69 | *static* `str.``maketrans`(*x*[, *y*[, *z*]])[¶](#str.maketrans "Permalink to this definition")
: This static method returns a translation table usable for [`str.translate()`](#str.translate "str.translate").
If there is only one argument, it must be a dictionary mapping Unicode
ordinals (integers) or charac... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
2664f106-df3b-5025-a658-292aa7ce2d19 | docs | python | python_stdtypes | 38 | 70 | after the separator. If the separator is not found, return a 3-tuple containing
the string itself, followed by two empty strings.
`str.``replace`(*old*, *new*[, *count*])[¶](#str.replace "Permalink to this definition")
: Return a copy of the string with all occurrences of substring *old* replaced by
*new... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
95bdac62-653f-5907-ba7f-b628da11260d | docs | python | python_stdtypes | 38 | 71 | `str.``rjust`(*width*[, *fillchar*])[¶](#str.rjust "Permalink to this definition")
: Return the string right justified in a string of length *width*. Padding is
done using the specified *fillchar* (default is an ASCII space). The
original string is returned if *width* is less than or equal to `len(s)`.
`str.... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
d6ad6d19-506f-5283-ac3b-c4fee269185b | docs | python | python_stdtypes | 38 | 72 | separator. Except for splitting from the right, [`rsplit()`](#str.rsplit "str.rsplit") behaves like
[`split()`](#str.split "str.split") which is described in detail below.
`str.``rstrip`([*chars*])[¶](#str.rstrip "Permalink to this definition")
: Return a copy of the string with trailing characters removed. ... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
a9831204-1ed9-581d-800e-5431d409f470 | docs | python | python_stdtypes | 38 | 73 | specified or `-1`, then there is no limit on the number of splits
(all possible splits are made).
If *sep* is given, consecutive delimiters are not grouped together and are
deemed to delimit empty strings (for example, `'1,,2'.split(',')` returns
`['1', '', '2']`). The *sep* argument may consist of... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
dc891240-b331-53f5-9bd3-c0efc03fdef4 | docs | python | python_stdtypes | 38 | 74 | string or a string consisting of just whitespace with a `None` separator
returns `[]`.
For example:
```None
>>> '1 2 3'.split()
['1', '2', '3']
>>> '1 2 3'.split(maxsplit=1)
['1', '2 3']
>>> ' 1 2 3 '.split()
['1', '2', '3']
```
`str.``splitlines`([*keepends*])[¶](... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
4ad75caf-e0ce-558d-9ec3-52de9837e34c | docs | python | python_stdtypes | 38 | 75 | | `\x1e` | Record Separator |
| `\x85` | Next Line (C1 Control Code) |
| `\u2028` | Line Separator |
| `\u2029` | Paragraph Separator |
Changed in version 3.2: `\v` and `\f` added to list of line boundaries.
For example:
```None
>>> 'ab c\n\nde fg\rkl\r\n'.splitlines()
['ab c', ''... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
440da8e2-2d95-5a22-8585-e11586d80257 | docs | python | python_stdtypes | 38 | 76 | : Return `True` if string starts with the *prefix*, otherwise return `False`.
*prefix* can also be a tuple of prefixes to look for. With optional *start*,
test string beginning at that position. With optional *end*, stop comparing
string at that position.
`str.``strip`([*chars*])[¶](#str.strip "Permalink... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
63be468c-1dbe-5e57-a750-e2171ed17018 | docs | python | python_stdtypes | 38 | 77 | reaching a string character that is not contained in the set of
characters in *chars*. A similar action takes place on the trailing end.
For example:
```None
>>> comment_string = '#....... Section 3.2.1 Issue #32 .......'
>>> comment_string.strip('.#! ')
'Section 3.2.1 Issue #32'
```
`... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
8f689c8e-caff-52f2-8099-2b59a538ffae | docs | python | python_stdtypes | 38 | 78 | it means that apostrophes in contractions and possessives form word
boundaries, which may not be the desired result:
```None
>>> "they're bill's friends from the UK".title()
"They'Re Bill'S Friends From The Uk"
```
A workaround for apostrophes can be constructed using regular expressions:
... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
58d0fa9c-9697-5cce-a8ec-53a962bc6a49 | docs | python | python_stdtypes | 38 | 79 | [sequence](../glossary.html#term-sequence). When indexed by a Unicode ordinal (an integer), the
table object can do any of the following: return a Unicode ordinal or a
string, to map the character to one or more other characters; return
`None`, to delete the character from the return string; or raise a
... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
f2a8702d-5a28-5660-8e05-40cf122ce132 | docs | python | python_stdtypes | 38 | 80 | contains uncased characters or if the Unicode category of the resulting
character(s) is not “Lu” (Letter, uppercase), but e.g. “Lt” (Letter,
titlecase).
The uppercasing algorithm used is described in section 3.13 of the Unicode
Standard.
`str.``zfill`(*width*)[¶](#str.zfill "Permalink to this defi... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
2560df46-6e73-5b08-8249-e76e0e8ad45b | docs | python | python_stdtypes | 38 | 81 | dictionaries correctly). Using the newer [formatted string literals](../reference/lexical_analysis.html#f-strings), the [`str.format()`](#str.format "str.format") interface, or [template strings](string.html#template-strings) may help avoid these errors. Each of these
alternatives provides their own trade-offs and bene... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
4a4a3d54-c670-5b5d-a754-f438ff3c0671 | docs | python | python_stdtypes | 38 | 82 | A conversion specifier contains two or more characters and has the following
components, which must occur in this order:
1. The `'%'` character, which marks the start of the specifier.
2. Mapping key (optional), consisting of a parenthesised sequence of characters
(for example, `(somename)`).
3. Conversion flags (o... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
a947a47d-5b08-503b-b9dd-87a098a4d313 | docs | python | python_stdtypes | 38 | 83 | formats in the string *must* include a parenthesised mapping key into that
dictionary inserted immediately after the `'%'` character. The mapping key
selects the value to be formatted from the mapping. For example:
```None
>>> print('%(language)s has %(number)03d quote types.' %
... {'language': "Python", "numbe... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
b0f573fb-887b-5f6b-bb89-5abed1e9e744 | docs | python | python_stdtypes | 38 | 84 | A length modifier (`h`, `l`, or `L`) may be present, but is ignored as it
is not necessary for Python – so e.g. `%ld` is identical to `%d`.
The conversion types are:
| Conversion | Meaning | Notes |
| --- | --- | --- |
| `'d'` | Signed integer decimal. | |
| `'i'` | Signed integer decimal. | |
| `'o'` | Signed octa... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
d1ed0e78-e2b8-5a91-8a22-c2621c4f2968 | docs | python | python_stdtypes | 38 | 85 | | `'G'` | Floating point format. Uses uppercase exponential format if exponent is less than -4 or not less than precision, decimal format otherwise. | (4) |
| `'c'` | Single character (accepts integer or single character string). | |
| `'r'` | String (converts any Python object using [`repr()`](functions.html#repr "re... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
0ccc90b7-177e-590d-92dc-09f9d745d634 | docs | python | python_stdtypes | 38 | 86 | 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_38.md |
581860ef-047e-59b3-9cc1-b119b847c473 | docs | python | python_stdtypes | 38 | 87 | The core built-in types for manipulating binary data are [`bytes`](#bytes "bytes") and
[`bytearray`](#bytearray "bytearray"). They are supported by [`memoryview`](#memoryview "memoryview") which uses
the [buffer protocol](../c-api/buffer.html#bufferobjects) to access the memory of other
binary objects without needing t... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
6eff01b1-a4f0-5f52-9b31-e448ff013857 | docs | python | python_stdtypes | 38 | 88 | : Firstly, the syntax for bytes literals is largely the same as that for string
literals, except that a `b` prefix is added:
* Single quotes: `b'still allows embedded "double" quotes'`
* Double quotes: `b"still allows embedded 'single' quotes"`.
* Triple quoted: `b'''3 single quotes'''`, `b"""3 doubl... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
7f5d6337-6a57-5fb0-a990-8cf6c21bdfaf | docs | python | python_stdtypes | 38 | 89 | value in the sequence restricted such that `0 <= x < 256` (attempts to
violate this restriction will trigger [`ValueError`](exceptions.html#ValueError "ValueError")). This is done
deliberately to emphasise that while many binary formats include ASCII based
elements and can be usefully manipulated with s... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
6d829f0c-090e-5a2b-9d9c-59167051e060 | docs | python | python_stdtypes | 38 | 90 | numbers are a commonly used format for describing binary data. Accordingly,
the bytes type has an additional class method to read data in that format:
*classmethod* `fromhex`(*string*)[¶](#bytes.fromhex "Permalink to this definition")
: This [`bytes`](#bytes "bytes") class method returns a bytes obje... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
5a1daf5a-aa42-547a-b107-0712e4c1190c | docs | python | python_stdtypes | 38 | 91 | ```None
>>> b'\xf0\xf1\xf2'.hex()
'f0f1f2'
```
If you want to make the hex string easier to read, you can specify a
single character separator *sep* parameter to include in the output.
By default between each byte. A second optional *bytes\_per\_sep*
para... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
5d2c6dd7-1dee-55a2-8903-c37e919247fe | docs | python | python_stdtypes | 38 | 92 | object *b*, `b[0]` will be an integer, while `b[0:1]` will be a bytes
object of length 1. (This contrasts with text strings, where both indexing
and slicing will produce a string of length 1)
The representation of bytes objects uses the literal format (`b'...'`)
since it is often more useful than e.g. `bytes([46, 46, ... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
c9e244a2-0d0c-5f2e-bb18-f4a289e196f1 | docs | python | python_stdtypes | 38 | 93 | ### Bytearray Objects[¶](#bytearray-objects "Permalink to this headline")
[`bytearray`](#bytearray "bytearray") objects are a mutable counterpart to [`bytes`](#bytes "bytes")
objects.
*class* `bytearray`([*source*[, *encoding*[, *errors*]]])[¶](#bytearray "Permalink to this definition")
: There is no dedicated lite... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
bbd94782-c98e-54dc-ba05-07992fa96d0d | docs | python | python_stdtypes | 38 | 94 | Since 2 hexadecimal digits correspond precisely to a single byte, hexadecimal
numbers are a commonly used format for describing binary data. Accordingly,
the bytearray type has an additional class method to read data in that format:
*classmethod* `fromhex`(*string*)[¶](#bytearray.fromhex "Permalink to ... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
48410284-04cd-573a-94b9-bce993e002fe | docs | python | python_stdtypes | 38 | 95 | `hex`([*sep*[, *bytes\_per\_sep*]])[¶](#bytearray.hex "Permalink to this definition")
: Return a string object containing two hexadecimal digits for each
byte in the instance.
```None
>>> bytearray(b'\xf0\xf1\xf2').hex()
'f0f1f2'
```
New in version 3.5.
... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
ec322f7c-2d02-5057-b711-ef32cb736817 | docs | python | python_stdtypes | 38 | 96 | `bytearray([46, 46, 46])`. You can always convert a bytearray object into
a list of integers using `list(b)`.
### Bytes and Bytearray Operations[¶](#bytes-and-bytearray-operations "Permalink to this headline")
Both bytes and bytearray objects support the [common](#typesseq-common)
sequence operations. They interopera... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
84706e19-901e-5bae-9dba-178b95ea3497 | docs | python | python_stdtypes | 38 | 97 | binary formats, and hence should be avoided when working with arbitrary
binary data. These restrictions are covered below.
Note
Using these ASCII based operations to manipulate binary data that is not
stored in an ASCII based format may lead to data corruption.
The following methods on bytes and bytearray objects ca... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
8a52ddc6-b599-5cb3-9106-4e11a7436ee3 | docs | python | python_stdtypes | 38 | 98 | `bytes.``decode`(*encoding="utf-8"*, *errors="strict"*)[¶](#bytes.decode "Permalink to this definition")
`bytearray.``decode`(*encoding="utf-8"*, *errors="strict"*)[¶](#bytearray.decode "Permalink to this definition")
: Return a string decoded from the given bytes. Default encoding is
`'utf-8'`. *errors* may be ... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
24ef752c-8fe2-59cb-90d6-c090bf4ad2bb | docs | python | python_stdtypes | 38 | 99 | [bytes-like object](../glossary.html#term-bytes-like-object) directly, without needing to make a temporary
bytes or bytearray object.
Changed in version 3.1: Added support for keyword arguments.
`bytes.``endswith`(*suffix*[, *start*[, *end*]])[¶](#bytes.endswith "Permalink to this definition")
`bytearray... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
111034cc-20d5-5f77-88e9-f8bbb4f80b12 | docs | python | python_stdtypes | 38 | 100 | : Return the lowest index in the data where the subsequence *sub* is found,
such that *sub* is contained in the slice `s[start:end]`. Optional
arguments *start* and *end* are interpreted as in slice notation. Return
`-1` if *sub* is not found.
The subsequence to search for may be any [bytes-like obje... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
7635fef3-55cf-5dc8-855a-553f63607ec0 | docs | python | python_stdtypes | 38 | 101 | : Like [`find()`](#bytes.find "bytes.find"), but raise [`ValueError`](exceptions.html#ValueError "ValueError") when the
subsequence is not found.
The subsequence to search for may be any [bytes-like object](../glossary.html#term-bytes-like-object) or an
integer in the range 0 to 255.
Changed in vers... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
6699e0c0-13f5-5472-9e55-5340510c3e69 | docs | python | python_stdtypes | 38 | 102 | *static* `bytes.``maketrans`(*from*, *to*)[¶](#bytes.maketrans "Permalink to this definition")
*static* `bytearray.``maketrans`(*from*, *to*)[¶](#bytearray.maketrans "Permalink to this definition")
: This static method returns a translation table usable for
[`bytes.translate()`](#bytes.translate "bytes.translate... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
231f3b29-2bd1-50bd-9fec-f864547272f5 | docs | python | python_stdtypes | 38 | 103 | containing a copy of the original sequence, followed by two empty bytes or
bytearray objects.
The separator to search for may be any [bytes-like object](../glossary.html#term-bytes-like-object).
`bytes.``replace`(*old*, *new*[, *count*])[¶](#bytes.replace "Permalink to this definition")
`bytearray.``repl... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
a22f387e-f608-5488-825b-7b344fa7a09b | docs | python | python_stdtypes | 38 | 104 | `bytearray.``rfind`(*sub*[, *start*[, *end*]])[¶](#bytearray.rfind "Permalink to this definition")
: Return the highest index in the sequence where the subsequence *sub* is
found, such that *sub* is contained within `s[start:end]`. Optional
arguments *start* and *end* are interpreted as in slice notation. Ret... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
3b3cedb8-76b4-5652-847a-a9d9945626f4 | docs | python | python_stdtypes | 38 | 105 | The subsequence to search for may be any [bytes-like object](../glossary.html#term-bytes-like-object) or an
integer in the range 0 to 255.
Changed in version 3.3: Also accept an integer in the range 0 to 255 as the subsequence.
`bytes.``rpartition`(*sep*)[¶](#bytes.rpartition "Permalink to this definition... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
b9af22d7-8803-54d6-95b5-9c7b7f074a75 | docs | python | python_stdtypes | 38 | 106 | `bytearray.``startswith`(*prefix*[, *start*[, *end*]])[¶](#bytearray.startswith "Permalink to this definition")
: Return `True` if the binary data starts with the specified *prefix*,
otherwise return `False`. *prefix* can also be a tuple of prefixes to
look for. With optional *start*, test beginning at that p... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
bfbf6b06-6bc0-5438-b32e-f7f1d4cdd4a0 | docs | python | python_stdtypes | 38 | 107 | You can use the [`bytes.maketrans()`](#bytes.maketrans "bytes.maketrans") method to create a translation
table.
Set the *table* argument to `None` for translations that only delete
characters:
```None
>>> b'read this short text'.translate(None, b'aeiou')
b'rd ths shrt txt'
```
Cha... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
d1bc526a-0b87-5906-848b-acf46523a5d7 | docs | python | python_stdtypes | 38 | 108 | Padding is done using the specified *fillbyte* (default is an ASCII
space). For [`bytes`](#bytes "bytes") objects, the original sequence is returned if
*width* is less than or equal to `len(s)`.
Note
The bytearray version of this method does *not* operate in place -
it always produces a new ob... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
15274ca2-96df-5e9b-93c0-966e001a1c4f | docs | python | python_stdtypes | 38 | 109 | `bytes.``lstrip`([*chars*])[¶](#bytes.lstrip "Permalink to this definition")
`bytearray.``lstrip`([*chars*])[¶](#bytearray.lstrip "Permalink to this definition")
: Return a copy of the sequence with specified leading bytes removed. The
*chars* argument is a binary sequence specifying the set of byte values to
... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
00ced9b0-0c80-5dbe-bbc0-48c31d8d054c | docs | python | python_stdtypes | 38 | 110 | `bytes.``rjust`(*width*[, *fillbyte*])[¶](#bytes.rjust "Permalink to this definition")
`bytearray.``rjust`(*width*[, *fillbyte*])[¶](#bytearray.rjust "Permalink to this definition")
: Return a copy of the object right justified in a sequence of length *width*.
Padding is done using the specified *fillbyte* (defa... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
6c48c87c-fe06-520a-be4a-a7dd36ef27eb | docs | python | python_stdtypes | 38 | 111 | are done, the *rightmost* ones. If *sep* is not specified or `None`,
any subsequence consisting solely of ASCII whitespace is a separator.
Except for splitting from the right, [`rsplit()`](#bytearray.rsplit "bytearray.rsplit") behaves like
[`split()`](#bytearray.split "bytearray.split") which is describ... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
d322d5cf-82c5-5b3d-b4dd-a4b12d83d73a | docs | python | python_stdtypes | 38 | 112 | >>> b'mississippi'.rstrip(b'ipz')
b'mississ'
```
The binary sequence of byte values to remove may be any
[bytes-like object](../glossary.html#term-bytes-like-object).
Note
The bytearray version of this method does *not* operate in place -
it always produces a new object, even if no ch... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
1312b98c-b0ad-597d-ad9b-12cd0befa727 | docs | python | python_stdtypes | 38 | 113 | deemed to delimit empty subsequences (for example, `b'1,,2'.split(b',')`
returns `[b'1', b'', b'2']`). The *sep* argument may consist of a
multibyte sequence (for example, `b'1<>2<>3'.split(b'<>')` returns
`[b'1', b'2', b'3']`). Splitting an empty sequence with a specified
separator returns `[b'']` ... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
87e47960-52d6-5532-b6e1-a042f5103df7 | docs | python | python_stdtypes | 38 | 114 | splitting an empty sequence or a sequence consisting solely of ASCII
whitespace without a specified separator returns `[]`.
For example:
```None
>>> b'1 2 3'.split()
[b'1', b'2', b'3']
>>> b'1 2 3'.split(maxsplit=1)
[b'1', b'2 3']
>>> b' 1 2 3 '.split()
[b'1', b'2', b'3... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
ca28ed0d-adf6-5be0-90fb-62dd2eab696f | docs | python | python_stdtypes | 38 | 115 | >>> b'www.example.com'.strip(b'cmowz.')
b'example'
```
The binary sequence of byte values to remove may be any
[bytes-like object](../glossary.html#term-bytes-like-object).
Note
The bytearray version of this method does *not* operate in place -
it always produces a new object, even if... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
dbd419b5-6620-570e-94ac-eb404979b97d | docs | python | python_stdtypes | 38 | 116 | The bytearray version of this method does *not* operate in place - it
always produces a new object, even if no changes were made.
`bytes.``expandtabs`(*tabsize=8*)[¶](#bytes.expandtabs "Permalink to this definition")
`bytearray.``expandtabs`(*tabsize=8*)[¶](#bytearray.expandtabs "Permalink to this definition"... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
c7e01e4a-ada0-5a08-8304-99f97e1adec4 | docs | python | python_stdtypes | 38 | 117 | carriage return (`b'\r'`), it is copied and the current column is reset
to zero. Any other byte value is copied unchanged and the current column
is incremented by one regardless of how the byte value is represented when
printed:
```None
>>> b'01\t012\t0123\t01234'.expandtabs()
b'01 012... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
12b36e76-3f29-50f0-854f-57371c8e7325 | docs | python | python_stdtypes | 38 | 118 | `b'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'`. ASCII decimal
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 "Permalink to this de... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
287ee6ec-998a-5922-824f-a08af2bdfdb5 | docs | python | python_stdtypes | 38 | 119 | `False` otherwise.
ASCII bytes are in the range 0-0x7F.
New in version 3.7.
`bytes.``isdigit`()[¶](#bytes.isdigit "Permalink to this definition")
`bytearray.``isdigit`()[¶](#bytearray.isdigit "Permalink to this definition")
: Return `True` if all bytes in the sequence are ASCII decimal digits
and t... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
688b0553-3c86-5b81-97ba-2fce0610b231 | docs | python | python_stdtypes | 38 | 120 | Lowercase ASCII characters are those byte values in the sequence
`b'abcdefghijklmnopqrstuvwxyz'`. Uppercase ASCII characters
are those byte values in the sequence `b'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`.
`bytes.``isspace`()[¶](#bytes.isspace "Permalink to this definition")
`bytearray.``isspace`()[¶](#bytearray.is... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
e85f06bd-d6d8-5227-9f46-f07d21cf91de | docs | python | python_stdtypes | 38 | 121 | ```None
>>> b'Hello World'.istitle()
True
>>> b'Hello world'.istitle()
False
```
`bytes.``isupper`()[¶](#bytes.isupper "Permalink to this definition")
`bytearray.``isupper`()[¶](#bytearray.isupper "Permalink to this definition")
: Return `True` if there is at least one uppercase alphabetic A... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
96f94942-dae5-565d-86c4-0314384ef7dc | docs | python | python_stdtypes | 38 | 122 | For example:
```None
>>> b'Hello World'.lower()
b'hello world'
```
Lowercase ASCII characters are those byte values in the sequence
`b'abcdefghijklmnopqrstuvwxyz'`. Uppercase ASCII characters
are those byte values in the sequence `b'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`.
Note
The byte... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
5aeb7b6b-795c-5725-a65c-3d38d9f022d1 | docs | python | python_stdtypes | 38 | 123 | [b'ab c', b'', b'de fg', b'kl']
>>> b'ab c\n\nde fg\rkl\r\n'.splitlines(keepends=True)
[b'ab c\n', b'\n', b'de fg\r', b'kl\r\n']
```
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... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
8f47ebec-0242-5309-a8e8-35037c404f27 | docs | python | python_stdtypes | 38 | 124 | `b'abcdefghijklmnopqrstuvwxyz'`. Uppercase ASCII characters
are those byte values in the sequence `b'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`.
Unlike [`str.swapcase()`](#str.swapcase "str.swapcase"), it is always the case that
`bin.swapcase().swapcase() == bin` for the binary versions. Case
conversions are sym... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
70b034b2-4f9c-5659-afd6-25dab8ea178d | docs | python | python_stdtypes | 38 | 125 | Lowercase ASCII characters are those byte values in the sequence
`b'abcdefghijklmnopqrstuvwxyz'`. Uppercase ASCII characters
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 wor... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
5ef58edd-ac58-5400-a2cb-292145d8ea1e | docs | python | python_stdtypes | 38 | 126 | >>> titlecase(b"they're bill's friends.")
b"They're Bill's Friends."
```
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.``upper`()[¶](#bytes.upper "Permalink to this definition")
`bytearray.``upper... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
f16b2800-e462-5ee9-8305-11db23d161fc | docs | python | python_stdtypes | 38 | 127 | `bytes.``zfill`(*width*)[¶](#bytes.zfill "Permalink to this definition")
`bytearray.``zfill`(*width*)[¶](#bytearray.zfill "Permalink to this definition")
: 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 handle... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
9906ef07-f224-5fe2-a850-eef86992f60a | docs | python | python_stdtypes | 38 | 128 | lead to a number of common errors (such as failing to display tuples and
dictionaries correctly). If the value being printed may be a tuple or
dictionary, wrap it in a tuple.
Bytes objects (`bytes`/`bytearray`) have one unique built-in operation:
the `%` operator (modulo).
This is also known as the bytes *formatting* ... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
3d4c3411-1ef4-5285-829b-ad3cc0812065 | docs | python | python_stdtypes | 38 | 129 | 2. Mapping key (optional), consisting of a parenthesised sequence of characters
(for example, `(somename)`).
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 o... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
612ed8c9-9044-51b2-987d-b8790db49d40 | docs | python | python_stdtypes | 38 | 130 | selects the value to be formatted from the mapping. For example:
```None
>>> print(b'%(language)s has %(number)03d quote types.' %
... {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).... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
68706b1c-cb7b-56b9-b726-05af96fc9fd5 | docs | python | python_stdtypes | 38 | 131 | The conversion types are:
| Conversion | Meaning | Notes |
| --- | --- | --- |
| `'d'` | Signed integer decimal. | |
| `'i'` | Signed integer decimal. | |
| `'o'` | Signed octal value. | (1) |
| `'u'` | Obsolete type – it is identical to `'d'`. | (8) |
| `'x'` | Signed hexadecimal (lowercase). | (2) |
| `'X'` | Sign... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
1f2dd881-c158-554b-961c-f9f9f7a5f996 | docs | python | python_stdtypes | 38 | 132 | | `'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_38.md |
64548c4f-bf18-5e41-bbbd-01fa007d418b | docs | python | python_stdtypes | 38 | 133 | 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_38.md |
d739efa7-fccb-58ff-8f4f-b5da1268ea69 | docs | python | python_stdtypes | 38 | 134 | ### Memory Views[¶](#memory-views "Permalink to this headline")
[`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`(*obj*)[¶](#memoryview "Permalink to ... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
af79591a-e84c-57c1-a7e5-8763765689a2 | docs | python | python_stdtypes | 38 | 135 | `len(view)` is equal to the length of [`tolist`](#memoryview.tolist "memoryview.tolist").
If `view.ndim = 0`, the length is 1. If `view.ndim = 1`, the length
is equal to the number of elements in the view. For higher dimensions,
the length is equal to the length of the nested list representation of
... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
56d24a75-190e-5e38-bae3-2ac135694277 | docs | python | python_stdtypes | 38 | 136 | 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-integer tupl... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
15bd4999-0cb2-5bec-92bc-5a45a5b55fcc | docs | python | python_stdtypes | 38 | 137 | >>> 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):
File "<stdin>", line 1, in <module>
ValueError: memoryview assi... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
7eee6f33-9915-5f06-b4d4-46344d2d2374 | docs | python | python_stdtypes | 38 | 138 | Changed in version 3.4: memoryview is now registered automatically with
[`collections.abc.Sequence`](collections.abc.html#collections.abc.Sequence "collections.abc.Sequence")
Changed in version 3.5: memoryviews can now be indexed with tuple of integers.
[`memoryview`](#memoryview "memoryview") has sev... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
c74517b0-16d3-5274-afb3-50053af7c0cd | docs | python | python_stdtypes | 38 | 139 | [`tolist()`](#memoryview.tolist "memoryview.tolist"), `v` and `w` are equal if `v.tolist() == w.tolist()`:
```None
>>> import array
>>> a = array.array('I', [1, 2, 3, 4, 5])
>>> b = array.array('d', [1.0, 2.0, 3.0, 4.0, 5.0])
>>> c = array.array('b', [5, 3, 1])
>... | large_dataset/raw/docs/python/stdtypes/stdtypes_38.md |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.