โ†Previous page

06TRUE OR FALSE? ยท IN

in: is it inside?

in looks inside a list or a word and answers True or False. not in asks the opposite.

IN REAL LIFE

You look inside things every day.

Is it in there? The answer is yes or no.

In the backpack?

Before school: is my water bottle in the backpack?

On the party list?

At the door: is my name on the guest list?

In the word?

In a word game: is there an a in banana?

LOOK FIRST

Three things to know about in.

in looks in a list

"apple" in bag is True when "apple" is one of the things in the bag list.

in looks in text too

"a" in "banana" is True. Capitals matter: "B" in "banana" is False.

not in: is it missing?

not in gives the opposite answer. It is True when the thing is not there.

A trick: in is like a pair of hands searching a box. Found it: True. Not there: False.

STEP BY STEP

How Python searches.

Python checks each thing in the list, one by one.

bag = ["book", "apple", "pencil"]A list with three things.
"apple" in bagbook? No. apple? Yes! Python answers True.
"ball" in bagPython checks all three. No ball, so False.
"ball" not in bagnot in flips it: the ball is missing, so True.

RUN IT

Is Leo on the list?

Guess first. Then run real Python and check.

1

Guess the result

guests = ["Ana", "Leo", "Sam"] if "Leo" in guests: print("come in!") else: print("sorry, not on the list")

What will Python show?

party.pyREAL PYTHON
OUTPUT
Ready. Press Run Python.
Python runs here thanks to Pyodide โ™ฅ

Pyodide 314.0.3 runs CPython in your browser with WebAssembly.

Open-source under the Mozilla Public License 2.0. License

Now change one thing: Change "Leo" to "leo" with a small l. What shows now? Then add "Mia" to the list and ask for her.

YOUR TURN

Is it inside?

Try each tiny question. A wrong answer becomes something to review.

0Completed
9Not tried
0Review
01

The shopping list

Shopping list: milk, eggs, bread. Dad asks: is cheese on the list?

What is the answer?

02

Find the cat

"cat" in ["dog", "cat", "fish"]

What does Python answer?

03

Find the bird

"bird" in ["dog", "cat", "fish"]

What does Python answer?

04

A letter in a word

"a" in "banana"

What does Python answer?

05

Big or small letters?

"py" in "PyBot"

What does Python answer?

06

Is z missing?

"z" not in "pizza"

What does Python answer?

07

Hello, new friend

PyBot says hello to new kids: kids who are NOT in the friends list yet. if name ___ friends:

Which word goes in the gap?

08

Fix PyBot's code

PyBot wants to know if the umbrella is in the bag. But == asks if the whole list is the umbrella. Change one word.

Goal output
ready for rain
OUTPUT

Your work is saved here.

Want a fresh start? Clear only this page.

!
BIG IDEA

in asks: is it inside? not in asks: is it missing?

Next, be a detective: mix everything you learned to solve logic challenges.