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 |
|---|---|---|---|---|---|---|---|
e79814e5-b0e0-5d04-8e04-548d76faff30 | docs | python | python_stdtypes | 39 | 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_39.md |
a5f79f92-b439-561c-b0bc-30a38bf7a058 | docs | python | python_stdtypes | 39 | 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_39.md |
d5254b64-2c79-5dcd-924c-f12dcfefb24b | docs | python | python_stdtypes | 39 | 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_39.md |
9c8e5abe-a2fa-579f-aa04-d41ece601412 | docs | python | python_stdtypes | 39 | 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_39.md |
51c53639-dfe6-5a5c-9c7d-4bf0ceb2f660 | docs | python | python_stdtypes | 39 | 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_39.md |
eb7acdcb-f5d4-5474-adcb-346a93a3e86d | docs | python | python_stdtypes | 39 | 46 | For a positive *step*, the contents of a range `r` are determined by the
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] > s... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
31fcb25a-61cc-5234-9de5-38d41eb95898 | docs | python | python_stdtypes | 39 | 47 | [0, 5, 10, 15, 20, 25]
>>> list(range(0, 10, 3))
[0, 3, 6, 9]
>>> 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 concaten... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
a23e17ee-6deb-5b90-8850-69807bf4b1c4 | docs | python | python_stdtypes | 39 | 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_39.md |
b501b71a-9619-56bb-ac66-91cb15ff938e | docs | python | python_stdtypes | 39 | 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_39.md |
19ee9c64-07bd-50f6-8dba-c2ed45588a07 | docs | python | python_stdtypes | 39 | 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_39.md |
cfb19398-00db-590e-90b1-41f7b0ed04f0 | docs | python | python_stdtypes | 39 | 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_39.md |
2c96196b-88cc-584f-9ec5-2707226daa72 | docs | python | python_stdtypes | 39 | 52 | depends on whether *encoding* or *errors* is given, as follows.
If neither *encoding* nor *errors* is given, `str(object)` returns
[`type(object).__str__(object)`](../reference/datamodel.html#object.__str__ "object.__str__"),
which is the “informal” or nicely
printable string representation of *obj... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
9f8a4427-0228-5398-8f00-bd24b6f94ad1 | docs | python | python_stdtypes | 39 | 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_39.md |
78179707-d577-5d8e-b904-eb94e5d9c61e | docs | python | python_stdtypes | 39 | 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_39.md |
fb860fd6-1a9b-5919-9954-a377f06ee922 | docs | python | python_stdtypes | 39 | 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_39.md |
3f996e96-de57-5c52-9459-368f32f6bbc5 | docs | python | python_stdtypes | 39 | 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_39.md |
21380c5a-6c16-5d30-8f88-2b1c2b645826 | docs | python | python_stdtypes | 39 | 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_39.md |
0ba35aad-5ebe-5f7e-9e33-63f4fbef4265 | docs | python | python_stdtypes | 39 | 58 | Changed in version 3.9: The *errors* is now checked in development mode and in debug mode.
`str.``endswith`(*suffix*[, *start*[, *end*]])[¶](#str.endswith "Permalink to this definition")
: Return `True` if the string ends with the specified *suffix*, otherwise return
`False`. *suffix* can also be a tuple of ... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
63416387-3cf0-506a-970b-70aa741062e2 | docs | python | python_stdtypes | 39 | 59 | in the result until the current column is equal to the next tab position.
(The tab character itself is not copied.) If the character is a newline
(`\n`) or return (`\r`), it is copied and the current column is reset to
zero. Any other character is copied unchanged and the current column is
increment... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
84cbbb75-4f47-56f2-acc3-9aab8c083b5c | docs | python | python_stdtypes | 39 | 60 | position of *sub*. To check if *sub* is a substring or not, use the
[`in`](../reference/expressions.html#in) operator:
```None
>>> 'Py' in 'Python'
True
```
`str.``format`(*\*args*, *\*\*kwargs*)[¶](#str.format "Permalink to this definition")
: Perform a string formatting operation. The stri... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
5a07b885-f3cf-558a-a2df-62abcb6ebbcc | docs | python | python_stdtypes | 39 | 61 | When formatting a number ([`int`](functions.html#int "int"), [`float`](functions.html#float "float"), [`complex`](functions.html#complex "complex"),
[`decimal.Decimal`](decimal.html#decimal.Decimal "decimal.Decimal") and subclasses) with the `n` type
(ex: `'{:n}'.format(1234)`), the function temporarily set... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
e4ef1e0a-5f0f-5ee2-92ec-809f2cf366dd | docs | python | python_stdtypes | 39 | 62 | if for example `mapping` is a dict subclass:
```None
>>> class Default(dict):
... def __missing__(self, key):
... return key
...
>>> '{name} was born in {country}'.format_map(Default(name='Guido'))
'Guido was born in country'
```
New in version 3.2.
`str.``index`(*... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
26c553e8-2621-56e0-bf14-722bcc78bb8f | docs | python | python_stdtypes | 39 | 63 | : Return `True` if all characters in the string are alphabetic and there is at least
one character, `False` otherwise. Alphabetic characters are those characters defined
in the Unicode character database as “Letter”, i.e., those with general category
property being one of “Lm”, “Lt”, “Lu”, “Ll”, or “Lo”. ... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
a8a564bc-fefc-5338-bdb4-bb1d40c83409 | docs | python | python_stdtypes | 39 | 64 | ZERO. Formally a decimal character is a character in the Unicode
General Category “Nd”.
`str.``isdigit`()[¶](#str.isdigit "Permalink to this definition")
: Return `True` if all characters in the string are digits and there is at least one
character, `False` otherwise. Digits include decimal characters an... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
b199fb80-5350-5c23-8a4c-307be9751bff | docs | python | python_stdtypes | 39 | 65 | identifier, such as [`def`](../reference/compound_stmts.html#def) and [`class`](../reference/compound_stmts.html#class).
Example:
```None
>>> from keyword import iskeyword
>>> 'hello'.isidentifier(), iskeyword('hello')
(True, False)
>>> 'def'.isidentifier(), iskeyword('def')
(True, Tr... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
9ff66878-80d2-5d54-a841-e164a7ea0c94 | docs | python | python_stdtypes | 39 | 66 | value Numeric\_Type=Digit, Numeric\_Type=Decimal or Numeric\_Type=Numeric.
`str.``isprintable`()[¶](#str.isprintable "Permalink to this definition")
: Return `True` if all characters in the string are printable or the string is
empty, `False` otherwise. Nonprintable characters are those characters defined
... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
5aaa2c9e-74b3-500d-9a3f-54bcdc9b5edd | docs | python | python_stdtypes | 39 | 67 | A character is *whitespace* if in the Unicode character database
(see [`unicodedata`](unicodedata.html#module-unicodedata "unicodedata: Access the Unicode Database.")), either its general category is `Zs`
(“Separator, space”), or its bidirectional class is one of `WS`,
`B`, or `S`.
`str.``istitle`()[¶]... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
76b973bf-962d-58db-968f-3615ffe26fd0 | docs | python | python_stdtypes | 39 | 68 | `str.``join`(*iterable*)[¶](#str.join "Permalink to this definition")
: Return a string which is the concatenation of the strings in *iterable*.
A [`TypeError`](exceptions.html#TypeError "TypeError") will be raised if there are any non-string values in
*iterable*, including [`bytes`](#bytes "bytes") objects. ... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
058aeee3-3c3b-57e8-a45e-2a960d80bd02 | docs | python | python_stdtypes | 39 | 69 | `str.``lstrip`([*chars*])[¶](#str.lstrip "Permalink to this definition")
: Return a copy of the string with leading characters removed. The *chars*
argument is a string specifying the set of characters to be removed. If omitted
or `None`, the *chars* argument defaults to removing whitespace. The *chars*
a... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
f9d8ba02-7f34-5b37-be51-ff15584f46b3 | docs | python | python_stdtypes | 39 | 70 | : 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 characters (strings of length 1) to Unicode ordinals,
strings (of arbitrary lengths) or `None`. Ch... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
076c21a5-5df2-5773-86e5-64981da164e3 | docs | python | python_stdtypes | 39 | 71 | the string itself, followed by two empty strings.
`str.``removeprefix`(*prefix*, */*)[¶](#str.removeprefix "Permalink to this definition")
: If the string starts with the *prefix* string, return
`string[len(prefix):]`. Otherwise, return a copy of the original
string:
```None
>>> 'TestHook'.remov... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
d572c21a-3a53-53ef-907a-dbd5213820c0 | docs | python | python_stdtypes | 39 | 72 | : Return a copy of the string with all occurrences of substring *old* replaced by
*new*. If the optional argument *count* is given, only the first *count*
occurrences are replaced.
`str.``rfind`(*sub*[, *start*[, *end*]])[¶](#str.rfind "Permalink to this definition")
: Return the highest index in the strin... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
cde24972-d66e-5e8d-b6f4-320bf02973da | docs | python | python_stdtypes | 39 | 73 | original string is returned if *width* is less than or equal to `len(s)`.
`str.``rpartition`(*sep*)[¶](#str.rpartition "Permalink to this definition")
: Split the string at the last occurrence of *sep*, and return a 3-tuple
containing the part before the separator, the separator itself, and the part
afte... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
dd392bbb-7ece-5dc6-94a6-2c82c00d4f28 | docs | python | python_stdtypes | 39 | 74 | `str.``rstrip`([*chars*])[¶](#str.rstrip "Permalink to this definition")
: Return a copy of the string with trailing characters removed. The *chars*
argument is a string specifying the set of characters to be removed. If omitted
or `None`, the *chars* argument defaults to removing whitespace. The *chars*
... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
3ee0930f-1fb9-5521-bf00-9bd4954e50b6 | docs | python | python_stdtypes | 39 | 75 | string. If *maxsplit* is given, at most *maxsplit* splits are done (thus,
the list will have at most `maxsplit+1` elements). If *maxsplit* is not
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 group... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
f22bb0e0-afee-5cbe-90cd-48de4866ff4a | docs | python | python_stdtypes | 39 | 76 | and the result will contain no empty strings at the start or end if the
string has leading or trailing whitespace. Consequently, splitting an empty
string or a string consisting of just whitespace with a `None` separator
returns `[]`.
For example:
```None
>>> '1 2 3'.split()
['1', '2',... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
75bf03a0-f114-57d3-9dab-13ba7be1a5dd | docs | python | python_stdtypes | 39 | 77 | | `\r\n` | Carriage Return + Line Feed |
| `\v` or `\x0b` | Line Tabulation |
| `\f` or `\x0c` | Form Feed |
| `\x1c` | File Separator |
| `\x1d` | Group Separator |
| `\x1e` | Record Separator |
| `\x85` | Next Line (C1 Control Code) |
| `\u2028` | Line Separator |
| `\u2029` | Para... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
3668b795-6ff2-59da-b390-89bbbf55307b | docs | python | python_stdtypes | 39 | 78 | ['']
>>> 'Two lines\n'.split('\n')
['Two lines', '']
```
`str.``startswith`(*prefix*[, *start*[, *end*]])[¶](#str.startswith "Permalink to this definition")
: Return `True` if string starts with the *prefix*, otherwise return `False`.
*prefix* can also be a tuple of prefixes to look for. With opt... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
cd6b771f-aaef-5559-bdbe-f969e94703db | docs | python | python_stdtypes | 39 | 79 | The outermost leading and trailing *chars* argument values are stripped
from the string. Characters are removed from the leading end until
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:
```Non... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
ec8231d2-85fa-581d-81fc-0b248b777b75 | docs | python | python_stdtypes | 39 | 80 | 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 possessives form word
boundaries, which may not be the desired result:
```None
>>> "they're bill's frie... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
bde24735-0d51-5c87-b8af-016688b11516 | docs | python | python_stdtypes | 39 | 81 | : Return a copy of the string in which each character has been mapped through
the given translation table. The table must be an object that implements
indexing via [`__getitem__()`](../reference/datamodel.html#object.__getitem__ "object.__getitem__"), typically a [mapping](../glossary.html#term-mapping) or
... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
838d15bf-3b04-5a0a-b21e-2cb08c0f330a | docs | python | python_stdtypes | 39 | 82 | See also the [`codecs`](codecs.html#module-codecs "codecs: Encode and decode data and streams.") module for a more flexible approach to custom
character mappings.
`str.``upper`()[¶](#str.upper "Permalink to this definition")
: Return a copy of the string with all the cased characters [4](#id15) converted to
... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
a0a1647e-5b76-5970-96be-576eb661d1fe | docs | python | python_stdtypes | 39 | 83 | or equal to `len(s)`.
For example:
```None
>>> "42".zfill(5)
'00042'
>>> "-42".zfill(5)
'-0042'
```
### `printf`-style String Formatting[¶](#printf-style-string-formatting "Permalink to this headline")
Note
The formatting operations described here exhibit a variety of quirks that
le... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
57f4e666-8767-5a50-8a68-b785029eb50f | docs | python | python_stdtypes | 39 | 84 | specifications in *format* are replaced with zero or more elements of *values*.
The effect is similar to using the `sprintf()` in the C language.
If *format* requires a single argument, *values* may be a single non-tuple
object. [5](#id16) Otherwise, *values* must be a tuple with exactly the number of
items specified ... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
37e65686-3ec8-506d-abda-725343e5caaf | docs | python | python_stdtypes | 39 | 85 | 5. Precision (optional), given as a `'.'` (dot) followed by the precision. If
specified as `'*'` (an asterisk), the actual precision is read from the next
element of the tuple in *values*, and the value to convert comes after the
precision.
6. Length modifier (optional).
7. Conversion type.
When the right arg... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
6f808ac4-9e82-58c5-ae7a-bb9d1c92409a | docs | python | python_stdtypes | 39 | 86 | | `'0'` | The conversion will be zero padded for numeric values. |
| `'-'` | The converted value is left adjusted (overrides the `'0'` conversion if both are given). |
| `' '` | (a space) A blank should be left before a positive number (or empty string) produced by a signed conversion. |
| `'+'` | A sign character (`'+... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
dfcf04dd-1e18-5050-837f-3b57a48d84c1 | docs | python | python_stdtypes | 39 | 87 | | `'f'` | Floating point decimal format. | (3) |
| `'F'` | Floating point decimal format. | (3) |
| `'g'` | Floating point format. Uses lowercase exponential format if exponent is less than -4 or not less than precision, decimal format otherwise. | (4) |
| `'G'` | Floating point format. Uses uppercase exponential forma... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
2e5bf19e-490c-592f-9db7-c23e2c9f0fcb | docs | python | python_stdtypes | 39 | 88 | 2. The alternate form causes a leading `'0x'` or `'0X'` (depending on whether
the `'x'` or `'X'` format was used) to be inserted before the first digit.
3. The alternate form causes the result to always contain a decimal point, even if
no digits follow it.
The precision determines the number of digits after t... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
d0e395e9-9dd9-5896-80b0-1891aa7f46bc | docs | python | python_stdtypes | 39 | 89 | ## Binary Sequence Types — [`bytes`](#bytes "bytes"), [`bytearray`](#bytearray "bytearray"), [`memoryview`](#memoryview "memoryview")[¶](#binary-sequence-types-bytes-bytearray-memoryview "Permalink to this headline")
The core built-in types for manipulating binary data are [`bytes`](#bytes "bytes") and
[`bytearray`](#... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
44b0ea84-982d-5a09-a648-27f1c8a5e326 | docs | python | python_stdtypes | 39 | 90 | several methods that are only valid when working with ASCII compatible
data and are closely related to string objects in a variety of other ways.
*class* `bytes`([*source*[, *encoding*[, *errors*]]])[¶](#bytes "Permalink to this definition")
: Firstly, the syntax for bytes literals is largely the same as that for st... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
b4a896e6-41be-515e-8a75-c147ae612bf9 | docs | python | python_stdtypes | 39 | 91 | forms of bytes literal, including supported escape sequences.
While bytes literals and representations are based on ASCII text, bytes
objects actually behave like immutable sequences of integers, with each
value in the sequence restricted such that `0 <= x < 256` (attempts to
violate this restricti... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
a2de0a91-8c14-5298-a612-071ab2297922 | docs | python | python_stdtypes | 39 | 92 | * Copying existing binary data via the buffer protocol: `bytes(obj)`
Also see the [bytes](functions.html#func-bytes) built-in.
Since 2 hexadecimal digits correspond precisely to a single byte, hexadecimal
numbers are a commonly used format for describing binary data. Accordingly,
the bytes type ha... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
efd1e1ad-0b15-5339-ba93-49bbe3cc4b8c | docs | python | python_stdtypes | 39 | 93 | hexadecimal representation.
`hex`([*sep*[, *bytes\_per\_sep*]])[¶](#bytes.hex "Permalink to this definition")
: Return a string object containing two hexadecimal digits for each
byte in the instance.
```None
>>> b'\xf0\xf1\xf2'.hex()
'f0f1f2'
```
If you w... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
22148d10-5ef5-5347-ab9a-050b4fe8a19e | docs | python | python_stdtypes | 39 | 94 | Changed in version 3.8: [`bytes.hex()`](#bytes.hex "bytes.hex") now supports optional *sep* and *bytes\_per\_sep*
parameters to insert separators between bytes in the hex output.
Since bytes objects are sequences of integers (akin to a tuple), for a bytes
object *b*, `b[0]` will be an integer, while `b... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
f864e9e5-f94f-5499-b106-1482c4f55a61 | docs | python | python_stdtypes | 39 | 95 | : There is no dedicated literal syntax for bytearray objects, instead
they are always created by calling the constructor:
* Creating an empty instance: `bytearray()`
* Creating a zero-filled instance with a given length: `bytearray(10)`
* From an iterable of integers: `bytearray(range(20))`
* Cop... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
daa228cc-9b4d-55ab-86d5-aab09ae0a72b | docs | python | python_stdtypes | 39 | 96 | *classmethod* `fromhex`(*string*)[¶](#bytearray.fromhex "Permalink to this definition")
: This [`bytearray`](#bytearray "bytearray") class method returns bytearray object, decoding
the given string object. The string must contain two hexadecimal digits
per byte, with ASCII whitespace being ign... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
54122255-7ff4-578c-9bb2-d55137c376f5 | docs | python | python_stdtypes | 39 | 97 | New in version 3.5.
Changed in version 3.8: Similar to [`bytes.hex()`](#bytes.hex "bytes.hex"), [`bytearray.hex()`](#bytearray.hex "bytearray.hex") now supports
optional *sep* and *bytes\_per\_sep* parameters to insert separators
between bytes in the hex output.
Since bytearray objects... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
5b8ffaf2-c05a-530f-a37a-a034e87b0aeb | docs | python | python_stdtypes | 39 | 98 | ### 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 interoperate not just with operands of the same
type, but with any [bytes-like object](../glossary.html#term-bytes-like-o... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
34f6b595-1b7c-5763-9039-d315142312b0 | docs | python | python_stdtypes | 39 | 99 | 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 can be used with
arbitrary binary data.
`bytes.``count`(*sub*[, *start*[, *end*]])[¶](#bytes.count "Permalink to this definition")
... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
c6931745-ab1f-5fe2-a02d-537fcf82d8dc | docs | python | python_stdtypes | 39 | 100 | `bytearray.``removeprefix`(*prefix*, */*)[¶](#bytearray.removeprefix "Permalink to this definition")
: If the binary data starts with the *prefix* string, return
`bytes[len(prefix):]`. Otherwise, return a copy of the original
binary data:
```None
>>> b'TestHook'.removeprefix(b'Test')
b'Hook'
... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
068ee825-3cb6-56f3-b2e6-cdc9b5d69c6a | docs | python | python_stdtypes | 39 | 101 | the original binary data:
```None
>>> b'MiscTests'.removesuffix(b'Tests')
b'Misc'
>>> b'TmpDirMixin'.removesuffix(b'Tests')
b'TmpDirMixin'
```
The *suffix* may be any [bytes-like object](../glossary.html#term-bytes-like-object).
Note
The bytearray version of this method does ... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
dea0cdd1-4baa-50ea-9882-78700aafbf90 | docs | python | python_stdtypes | 39 | 102 | `'ignore'`, `'replace'` and any other name registered via
[`codecs.register_error()`](codecs.html#codecs.register_error "codecs.register_error"), see section [Error Handlers](codecs.html#error-handlers). For a
list of possible encodings, see section [Standard Encodings](codecs.html#standard-encodings).
... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
9970f96d-4c4f-58eb-b152-016059864d5c | docs | python | python_stdtypes | 39 | 103 | `bytes.``endswith`(*suffix*[, *start*[, *end*]])[¶](#bytes.endswith "Permalink to this definition")
`bytearray.``endswith`(*suffix*[, *start*[, *end*]])[¶](#bytearray.endswith "Permalink to this definition")
: Return `True` if the binary data ends with the specified *suffix*,
otherwise return `False`. *suffix* c... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
419ec692-3f44-561a-9cf6-fd307e26f2b3 | docs | python | python_stdtypes | 39 | 104 | `-1` if *sub* 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.
Note
The [`find()`](#bytes.find "bytes.find") method should be used only if you need to know the
position of *sub*. To check i... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
c73b91d2-fd51-5e08-b5ed-47aefc38e118 | docs | python | python_stdtypes | 39 | 105 | 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.``join`(*iterable*)[¶](#bytes.join "Permalink to this definition")
`bytearray.``join`(*iterable*)[¶](#bytearray.join "Permalink to this definition")
: Return a bytes or bytearray o... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
dedd5b8f-ec48-5e0a-8864-35b1f6af12e6 | docs | python | python_stdtypes | 39 | 106 | [`bytes.translate()`](#bytes.translate "bytes.translate") that will map each character in *from* into the
character at the same position in *to*; *from* and *to* must both be
[bytes-like objects](../glossary.html#term-bytes-like-object) and have the same length.
New in version 3.1.
`bytes.``partition`... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
2d47d4e5-ada3-5549-81d8-d39b49323e8b | docs | python | python_stdtypes | 39 | 107 | `bytes.``replace`(*old*, *new*[, *count*])[¶](#bytes.replace "Permalink to this definition")
`bytearray.``replace`(*old*, *new*[, *count*])[¶](#bytearray.replace "Permalink to this definition")
: Return a copy of the sequence with all occurrences of subsequence *old*
replaced by *new*. If the optional argument *... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
ace9fdcd-013e-5a17-9de1-2c17f36a428d | docs | python | python_stdtypes | 39 | 108 | arguments *start* and *end* are interpreted as in slice notation. Return
`-1` on failure.
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 ... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
f0f8ae7a-415b-523a-b4b6-cc1412286819 | docs | python | python_stdtypes | 39 | 109 | `bytearray.``rpartition`(*sep*)[¶](#bytearray.rpartition "Permalink to this definition")
: Split the sequence at the last occurrence of *sep*, and return a 3-tuple
containing the part before the separator, the separator itself or its
bytearray copy, and the part after the separator.
If the separator is no... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
135cf23e-b9c2-57cf-8c5f-82f18c4eab07 | docs | python | python_stdtypes | 39 | 110 | optional *end*, stop comparing at that position.
The prefix(es) to search for may be any [bytes-like object](../glossary.html#term-bytes-like-object).
`bytes.``translate`(*table*, */*, *delete=b''*)[¶](#bytes.translate "Permalink to this definition")
`bytearray.``translate`(*table*, */*, *delete=b''*)[¶](#by... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
e12050a4-58a9-5c36-832b-233e6e9276c4 | docs | python | python_stdtypes | 39 | 111 | The following methods on bytes and bytearray objects have default behaviours
that assume the use of ASCII compatible binary formats, but can still be used
with arbitrary binary data by passing appropriate arguments. Note that all of
the bytearray methods in this section do *not* operate in place, and instead
produce ne... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
6a759764-0d79-5d70-80b7-ff16b4d5b152 | docs | python | python_stdtypes | 39 | 112 | `bytes.``ljust`(*width*[, *fillbyte*])[¶](#bytes.ljust "Permalink to this definition")
`bytearray.``ljust`(*width*[, *fillbyte*])[¶](#bytearray.ljust "Permalink to this definition")
: Return a copy of the object left justified in a sequence of length *width*.
Padding is done using the specified *fillbyte* (defau... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
ad4c9429-49c7-5ce4-b913-aea9bbf0f87a | docs | python | python_stdtypes | 39 | 113 | ASCII characters. If omitted or `None`, the *chars* argument defaults
to removing ASCII whitespace. The *chars* argument is not a prefix;
rather, all combinations of its values are stripped:
```None
>>> b' spacious '.lstrip()
b'spacious '
>>> b'www.example.com'.lstrip(b'cmowz.')
b... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
20d48c4e-341b-5a78-9e1d-655147a585f7 | docs | python | python_stdtypes | 39 | 114 | `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_39.md |
8b830bd3-a72f-59f7-ae40-3f809a83697b | docs | python | python_stdtypes | 39 | 115 | 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_39.md |
6820583a-6051-52a3-b01c-cf5dd5759913 | docs | python | python_stdtypes | 39 | 116 | >>> 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). See [`removesuffix()`](#bytes.removesuffix "bytes.removesuffix") for a method
that will remove a single suffix string rather tha... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
d65a21d6-d5e2-54c8-b0a4-9c7509a314f4 | docs | python | python_stdtypes | 39 | 117 | *maxsplit* splits are done (thus, the list will have at most `maxsplit+1`
elements). If *maxsplit* is not specified or is `-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... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
4fdb0508-7751-5596-9492-a8f46aa21845 | docs | python | python_stdtypes | 39 | 118 | If *sep* is not specified or is `None`, a different splitting algorithm
is applied: runs of consecutive ASCII whitespace are regarded as a single
separator, and the result will contain no empty strings at the start or
end if the sequence has leading or trailing whitespace. Consequently,
splitting an... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
779a1a58-42ee-52b4-874c-82005b52ccd6 | docs | python | python_stdtypes | 39 | 119 | usually used with ASCII characters. If omitted or `None`, the *chars*
argument defaults to removing ASCII whitespace. The *chars* argument is
not a prefix or suffix; rather, all combinations of its values are
stripped:
```None
>>> b' spacious '.strip()
b'spacious'
>>> b'www.example.... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
dd530ac7-4b14-5b71-b381-86a6a5386c24 | docs | python | python_stdtypes | 39 | 120 | `bytearray.``capitalize`()[¶](#bytearray.capitalize "Permalink to this definition")
: Return a copy of the sequence with each byte interpreted as an ASCII
character, and the first byte capitalized and the rest lowercased.
Non-ASCII byte values are passed through unchanged.
Note
The bytearray version... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
0738003c-175a-5156-aa49-b12c89f1758e | docs | python | python_stdtypes | 39 | 121 | byte by byte. If the byte is an ASCII tab character (`b'\t'`), one or
more space characters are inserted in the result until the current column
is equal to the next tab position. (The tab character itself is not
copied.) If the current byte is an ASCII newline (`b'\n'`) or
carriage return (`b'\r'`),... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
a867a94e-ffe6-50b0-8c73-77de7504c598 | docs | python | python_stdtypes | 39 | 122 | : Return `True` if all bytes in the sequence are alphabetical ASCII characters
or ASCII decimal digits and the sequence is not empty, `False` otherwise.
Alphabetic ASCII characters are those byte values in the sequence
`b'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'`. ASCII decimal
digits are... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
1d659014-5bc6-5429-bbb3-0052134ae3df | docs | python | python_stdtypes | 39 | 123 | `bytes.``isascii`()[¶](#bytes.isascii "Permalink to this definition")
`bytearray.``isascii`()[¶](#bytearray.isascii "Permalink to this definition")
: Return `True` if the sequence is empty or all bytes in the sequence are ASCII,
`False` otherwise.
ASCII bytes are in the range 0-0x7F.
New in version 3.7.... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
b122088d-74d9-5a1f-b984-521b0643ad91 | docs | python | python_stdtypes | 39 | 124 | in the sequence and no uppercase ASCII characters, `False` otherwise.
For example:
```None
>>> b'hello world'.islower()
True
>>> b'Hello world'.islower()
False
```
Lowercase ASCII characters are those byte values in the sequence
`b'abcdefghijklmnopqrstuvwxyz'`. Uppercase ASCII... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
d805ebf0-9da1-5632-81d8-a6d3ddad8a09 | docs | python | python_stdtypes | 39 | 125 | : Return `True` if the sequence is ASCII titlecase and the sequence is not
empty, `False` otherwise. See [`bytes.title()`](#bytes.title "bytes.title") for more details on the
definition of “titlecase”.
For example:
```None
>>> b'Hello World'.istitle()
True
>>> b'Hello world'.istitle()
... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
bfe2b59b-1ba0-5827-867c-63d32bd84b20 | docs | python | python_stdtypes | 39 | 126 | `bytes.``lower`()[¶](#bytes.lower "Permalink to this definition")
`bytearray.``lower`()[¶](#bytearray.lower "Permalink to this definition")
: Return a copy of the sequence with all the uppercase ASCII characters
converted to their corresponding lowercase counterpart.
For example:
```None
>>> b'Hell... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
9fce4710-9d14-5597-9d8e-70df9fab9689 | docs | python | python_stdtypes | 39 | 127 | line boundaries. This method uses the [universal newlines](../glossary.html#term-universal-newlines) approach
to splitting lines. Line breaks are not included in the resulting list
unless *keepends* is given and true.
For example:
```None
>>> b'ab c\n\nde fg\rkl\r\n'.splitlines()
[b'ab c',... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
4d455ebf-fe8a-5e80-806b-efab6a6c0336 | docs | python | python_stdtypes | 39 | 128 | : Return a copy of the sequence with all the lowercase ASCII characters
converted to their corresponding uppercase counterpart and vice-versa.
For example:
```None
>>> b'Hello World'.swapcase()
b'hELLO wORLD'
```
Lowercase ASCII characters are those byte values in the sequence
`b'ab... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
c08e6d2a-22ea-5a61-8c9e-70186e22a36a | docs | python | python_stdtypes | 39 | 129 | : Return a titlecased version of the binary sequence where words start with
an uppercase ASCII character and the remaining characters are lowercase.
Uncased byte values are left unmodified.
For example:
```None
>>> b'Hello world'.title()
b'Hello World'
```
Lowercase ASCII characters... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
91d98be1-6acf-51a1-9058-cdec6a5a0db4 | docs | python | python_stdtypes | 39 | 130 | ```None
>>> import re
>>> def titlecase(s):
... return re.sub(rb"[A-Za-z]+('[A-Za-z]+)?",
... lambda mo: mo.group(0)[0:1].upper() +
... mo.group(0)[1:].lower(),
... s)
...
>>> titlecase(b"they're bill's friends.")
... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
d5ba1504-5636-594e-9ff1-df34d83f95d1 | docs | python | python_stdtypes | 39 | 131 | 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.``zfill`(*width*)[¶](#bytes.zfill "Permalink to this definition")
`bytearray.``zfill`(*... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
ac0f5a62-68bc-5ff3-b38e-9b758fdebfa4 | docs | python | python_stdtypes | 39 | 132 | ### `printf`-style Bytes Formatting[¶](#printf-style-bytes-formatting "Permalink to this headline")
Note
The formatting operations described here exhibit a variety of quirks that
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... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
7061ee1c-20d1-5c14-b5bf-378126b6a5d8 | docs | python | python_stdtypes | 39 | 133 | 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_39.md |
83817cb3-63e4-573f-90e4-ecc3e0409c69 | docs | python | python_stdtypes | 39 | 134 | formats in the bytes object *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(b'%(language)s has %(number)03d quote types.' %
... {b'language': b"Python... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
65194162-f402-5655-882c-4e93b715f7d2 | docs | python | python_stdtypes | 39 | 135 |
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 oct... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
6559c26f-c62e-5d72-883e-396020e7ff56 | docs | python | python_stdtypes | 39 | 136 | | `'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 byte (accepts integer or single byte objects). | |
| `'b'` | Bytes (any object that follows the [buffer protocol](../c-api/buffer.html#bufferobje... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
3d913f91-a308-5abb-874a-cf800397ccc1 | docs | python | python_stdtypes | 39 | 137 | the `'x'` or `'X'` format was used) to be inserted before the first digit.
3. The alternate form causes the result to always contain a decimal point, even if
no digits follow it.
The precision determines the number of digits after the decimal point and
defaults to 6.
4. The alternate form causes the result... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
19e0b462-e472-5125-8a64-5ebd08bc525b | docs | python | python_stdtypes | 39 | 138 | [**PEP 461**](https://www.python.org/dev/peps/pep-0461) - Adding % formatting to bytes and bytearray
New in version 3.5.
### 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 [buffe... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
6bdfbd62-a4d2-5b67-86a5-8f33e8a22b9c | docs | python | python_stdtypes | 39 | 139 | byte, but other types such as [`array.array`](array.html#array.array "array.array") may have bigger elements.
`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 ... | large_dataset/raw/docs/python/stdtypes/stdtypes_39.md |
d400703d-c35c-5833-a7ab-6d636360e767 | docs | python | python_stdtypes | 39 | 140 | 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_39.md |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.