Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Accessing Elements of a Tuple | Tuple
course content

Conteúdo do Curso

Python Data Structures

Accessing Elements of a TupleAccessing Elements of a Tuple

Accessing elements in a tuple is straightforward and works the same way as with lists. Simply specify the index number inside square brackets. Remember, indexing starts at 0, just like with lists.

Tuples also support negative indexing, where the indexing begins from the end. Thus, the last element has an index of -1, the second to last is -2, and so on.

In the example above, we access the last element (indexed at -1) and the fourth element from the end (indexed at -4).

Tarefa

Given the tuple:

Retrieve the first, second, fifth, and seventh items to create a new tuple:

Tudo estava claro?

Seção 3. Capítulo 2
toggle bottom row
course content

Conteúdo do Curso

Python Data Structures

Accessing Elements of a TupleAccessing Elements of a Tuple

Accessing elements in a tuple is straightforward and works the same way as with lists. Simply specify the index number inside square brackets. Remember, indexing starts at 0, just like with lists.

Tuples also support negative indexing, where the indexing begins from the end. Thus, the last element has an index of -1, the second to last is -2, and so on.

In the example above, we access the last element (indexed at -1) and the fourth element from the end (indexed at -4).

Tarefa

Given the tuple:

Retrieve the first, second, fifth, and seventh items to create a new tuple:

Tudo estava claro?

Seção 3. Capítulo 2
toggle bottom row
some-alt