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

Contenido del Curso

Python Data Structures

Accessing the Elements of a SetAccessing the Elements of a Set

Since a set is an unordered collection, you can't access its elements by index because they don't have indices. However, you can verify whether an element exists within the set using the in keyword.

It's especially handy to use the in keyword with a for loop. Let's check out an example.

Tarea

Here's your set:

You need to determine if "pear", "banana", and "lemon" are in the set.

¿Todo estuvo claro?

Sección 4. Capítulo 4
toggle bottom row
course content

Contenido del Curso

Python Data Structures

Accessing the Elements of a SetAccessing the Elements of a Set

Since a set is an unordered collection, you can't access its elements by index because they don't have indices. However, you can verify whether an element exists within the set using the in keyword.

It's especially handy to use the in keyword with a for loop. Let's check out an example.

Tarea

Here's your set:

You need to determine if "pear", "banana", and "lemon" are in the set.

¿Todo estuvo claro?

Sección 4. Capítulo 4
toggle bottom row
some-alt