Two simple if-else codes in Python, should they not return the same value? Why each one returns something else.
def letter_check(word, letter):
for i in word:
if i == letter:
return True
return False
# This returns True
print(letter_check("strawberry", "a"))
# Same function?
def letter_check(word, letter):
for i in word:
if i == letter:
return True
else:
return False
# This returns False
print(letter_check("strawberry", "a"))
Aucun commentaire:
Enregistrer un commentaire