In the backpack?
Before school: is my water bottle in the backpack?
06TRUE OR FALSE? ยท IN
in looks inside a list or a word and answers True or False. not in asks the opposite.
IN REAL LIFE
Is it in there? The answer is yes or no.
Before school: is my water bottle in the backpack?
At the door: is my name on the guest list?
In a word game: is there an a in banana?
LOOK FIRST
"apple" in bag is True when "apple" is one of the things in the bag list.
"a" in "banana" is True. Capitals matter: "B" in "banana" is False.
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
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
Guess first. Then run real Python and check.
guests = ["Ana", "Leo", "Sam"]
if "Leo" in guests:
print("come in!")
else:
print("sorry, not on the list")What will Python show?
PyBot's hint
Ready. Press Run Python.
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
Try each tiny question. A wrong answer becomes something to review.
What is the answer?
"cat" in ["dog", "cat", "fish"]What does Python answer?
"bird" in ["dog", "cat", "fish"]What does Python answer?
"a" in "banana"What does Python answer?
"py" in "PyBot"What does Python answer?
"z" not in "pizza"What does Python answer?
Which word goes in the gap?
PyBot wants to know if the umbrella is in the bag. But == asks if the whole list is the umbrella. Change one word.
ready for rainOUTPUT
Want a fresh start? Clear only this page.
Next, be a detective: mix everything you learned to solve logic challenges.