I am watching a tutorial video on Youtube about Python basics. During the video he creates a lists and writes a code to print out "Found" if there are any words beginning with the letter "J".
Here is the code:
names = ["John", "Mary"]
found = False
for name in names:
if name.startswith("J"):
print("Found")
found = True
break
if not found:
print("Not found")
My question is why he decided to set the variable found to False at the beginning of the code if he then changes it to True towards the bottom?
Aucun commentaire:
Enregistrer un commentaire