| <html devsite> |
| <head> |
| <meta name="project_path" value="/_project.yaml"> |
| <meta name="book_path" value="/versions/6.1.0/_book.yaml"> |
| </head> |
| <body> |
| |
| <h1 class="page-title" id="modules.tuple">tuple</h1> |
| |
| <!-- {% raw %} --> |
| |
| The built-in tuple type. Example tuple expressions:<br><pre class=language-python>x = (1, 2, 3)</pre>Accessing elements is possible using indexing (starts from <code>0</code>):<br><pre class=language-python>e = x[1] # e == 2</pre>Lists support the <code>+</code> operator to concatenate two tuples. Example:<br><pre class=language-python>x = (1, 2) + (3, 4) # x == (1, 2, 3, 4) |
| x = ("a", "b") |
| x += ("c",) # x == ("a", "b", "c")</pre>Similar to lists, tuples support slice operations:<pre class=language-python>('a', 'b', 'c', 'd')[1:3] # ('b', 'c') |
| ('a', 'b', 'c', 'd')[::2] # ('a', 'c') |
| ('a', 'b', 'c', 'd')[3:0:-1] # ('d', 'c', 'b')</pre>Tuples are immutable, therefore <code>x[1] = "a"</code> is not supported. |
| |
| |
| |
| </body> |
| </html> |
| |
| <!-- {% endraw %} --> |