Puzzle 15 Where’s Waldo?
Python Brain Teasers — by Miki Tebeka (24 / 40)
Published in
2 min readMar 23, 2022
👈 The Great Divide | TOC | Call Me Maybe 👉
name = 'Waldo'
text = 'Can you find where Wally is?'
if text.find(name):
print('Found Waldo')
else:
print('Cannot find Waldo')
Guess the Output
IMPORTANT
Try to guess what the output is before moving to the next page.
This code will print: Found Waldo
The str.find documentation says
Return -1 if sub is not found.
We have two Boolean values in Python: True and False. They weren’t always there; they were added in Python 2.3.
How can you do logical operations without True and False? There are rules! Everything is True except
- 0 numbers: 0, 0.0, 0+0j, …
- Empty collections: [], {}, ”, …
- None
- False
You can test the truth value of a Python object using the built-in bool function.