| 1 |
.. _tuple-ops: |
| 2 |
|
| 3 |
Native tuple operations |
| 4 |
======================= |
| 5 |
|
| 6 |
These ``tuple`` operations have fast, optimized implementations. Other |
| 7 |
tuple operations use generic implementations that are often slower. |
| 8 |
|
| 9 |
Unless mentioned otherwise, these operations apply to both fixed-length |
| 10 |
tuples and variable-length tuples. |
| 11 |
|
| 12 |
Construction |
| 13 |
------------ |
| 14 |
|
| 15 |
* ``item0, ..., itemN`` (construct a tuple) |
| 16 |
* ``tuple(lst: list)`` (construct a variable-length tuple) |
| 17 |
* ``tuple(lst: Iterable)`` (construct a variable-length tuple) |
| 18 |
|
| 19 |
Operators |
| 20 |
--------- |
| 21 |
|
| 22 |
* ``tup[n]`` (integer index) |
| 23 |
* ``tup[n:m]``, ``tup[n:]``, ``tup[:m]`` (slicing) |
| 24 |
* ``tup1 + tup2`` |
| 25 |
* ``tup * n``, ``n * tup`` |
| 26 |
|
| 27 |
Statements |
| 28 |
---------- |
| 29 |
|
| 30 |
* ``item0, ..., itemN = tup`` (for fixed-length tuples) |
| 31 |
|
| 32 |
Functions |
| 33 |
--------- |
| 34 |
|
| 35 |
* ``len(tup: tuple)`` |