PYTHON CORE · LESSON 31

Is there an element?

Testing in · about 10 minutes

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

Search within the list

The word in asks if there is a thing on the list. The answer is True or False.

colors = ["синий", "зелёный"]
print("синий" in colors)
Finding value
Look.синийListсиний, зелёныйAnswerTrue

✦ True: Blue is on the list.

STEP 2

Search fits the conditions

The test result can be used in if.

pets = ["кот", "пёс"]
if "кот" in pets:
    print("Нашли кота")

✦ The program will find the cat.

IN-CLASS PRACTICE

Type the code yourself

Reprint the word check on the list.

pets = ["кот", "пёс"]
print("кот" in pets)
Open the editor for class work
HOMEWORK

Solve it yourself

Create pets from «кот», «пёс», «хомяк». Is there a «хомяк» in pets?

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

Opening up your homework