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
Python Data Structures
course content

Course Content

Python Data Structures

Python Data Structures

1. List
2. Dictionary
3. Tuple
4. Set
5. For deleting

bookAccessing 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.

123
countries = ('India', 'Latvia', 'Panama', 'Serbia', 'Finland', 'Germany', 'Japan') print(countries[1]) print(countries[5])
copy

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.

123
countries = ('India', 'Latvia', 'Panama', 'Serbia', 'Finland', 'Germany', 'Japan') print(countries[-1]) print(countries[-4])
copy

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

Task

Given the tuple:

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

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 3. Chapter 2
toggle bottom row

bookAccessing 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.

123
countries = ('India', 'Latvia', 'Panama', 'Serbia', 'Finland', 'Germany', 'Japan') print(countries[1]) print(countries[5])
copy

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.

123
countries = ('India', 'Latvia', 'Panama', 'Serbia', 'Finland', 'Germany', 'Japan') print(countries[-1]) print(countries[-4])
copy

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

Task

Given the tuple:

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

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 3. Chapter 2
toggle bottom row

bookAccessing 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.

123
countries = ('India', 'Latvia', 'Panama', 'Serbia', 'Finland', 'Germany', 'Japan') print(countries[1]) print(countries[5])
copy

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.

123
countries = ('India', 'Latvia', 'Panama', 'Serbia', 'Finland', 'Germany', 'Japan') print(countries[-1]) print(countries[-4])
copy

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

Task

Given the tuple:

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

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

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.

123
countries = ('India', 'Latvia', 'Panama', 'Serbia', 'Finland', 'Germany', 'Japan') print(countries[1]) print(countries[5])
copy

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.

123
countries = ('India', 'Latvia', 'Panama', 'Serbia', 'Finland', 'Germany', 'Japan') print(countries[-1]) print(countries[-4])
copy

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

Task

Given the tuple:

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

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Section 3. Chapter 2
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
some-alt