PYTHON CORE · LESSON 29

Just different things.

A set of set · about 11 minutes

Learning with progressRead the summary for free. To save the work, log in to the account.
STEP 1

Repeats disappear

The set only holds different meanings. Figure brackets here without pairs «ключ: значение».

nums = {1, 1, 2}
print(len(nums))

✦ Two different numbers.

STEP 2

Check if there's a thing.

The word in checks whether the value is inside the set.

colors = {"синий", "зелёный"}
print("синий" in colors)

✦ Answer True.

IN-CLASS PRACTICE

Type the code yourself

Reprint a set and count different meanings.

nums = {2, 2, 3}
print(len(nums))
Open the editor for class work
HOMEWORK

Solve it yourself

Create a set of nums from 1, 1, 2, 3. Infer the number of different numbers using len.

The answer is hidden. Use similar examples from the lesson notes.

Opening up your homework