bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Python/Foundations
Python•Foundations

Python - Access Set Items

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind Python - Access Set Items?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___ = {"apple", "banana", "cherry"}
3Order

Put the learning moves in the order that makes the concept easiest to apply.

Once a set is created, you cannot change its items, but you can add new items.
But you can loop through the set items using a for loop, or ask if a specified value is present in a set, by using the in keyword.
You cannot access items in a set by referring to an index or a key.

Access Items

You cannot access items in a set by referring to an index or a key.

But you can loop through the set items using a for loop, or ask if a specified value is present in a set, by using the in keyword.

Example

thisset = {"apple", "banana", "cherry"}
for x in thisset:
  print(x)

Example

thisset = {"apple", "banana", "cherry"}
print("banana"
in thisset)

Example

thisset = {"apple", "banana", "cherry"}
print("banana"
not in thisset)

Change Items

Once a set is created, you cannot change its items, but you can add new items.

Previous

Python Sets

Next

Python - Add Set Items