File: bytes_operations.rst

package info (click to toggle)
mypy 1.15.0-5
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 20,576 kB
  • sloc: python: 105,159; cpp: 11,380; ansic: 6,629; makefile: 247; sh: 20
file content (46 lines) | stat: -rw-r--r-- 801 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
.. _bytes-ops:

Native bytes operations
========================

These ``bytes`` operations have fast, optimized implementations. Other
bytes operations use generic implementations that are often slower.

Construction
------------

* Bytes literal
* ``bytes(x: list)``

Operators
---------

* Concatenation (``b1 + b2``)
* Indexing (``b[n]``)
* Slicing (``b[n:m]``, ``b[n:]``, ``b[:m]``)
* Comparisons (``==``, ``!=``)

.. _bytes-methods:

Methods
-------

* ``b.decode()``
* ``b.decode(encoding: str)``
* ``b.decode(encoding: str, errors: str)``
* ``b.join(x: Iterable)``

.. note::

    :ref:`str.encode() <str-methods>` is also optimized.

Formatting
----------

A subset of % formatting operations are optimized (``b"..." % (...)``).

Functions
---------

* ``len(b: bytes)``
* ``ord(b: bytes)``