Why is there no output upon calling the defined function?

def letter_check(word, letter):
for character in word:
if character == letter:
return True
return False
letter_check(“strawberry”, “a”)
In the context of this exercise and code, I cant figure out why upon calling the function letter check I am not receiving any output of true or false

In the future please look at properly formatting your code as this preserves indentation (which is very important in Python) and leaves it ready to be used in an IDE.

To format your code, simply press this button:

Than copy/paste your code between the two rows of backticks:

Your function is in actually returning, you cannot see the result though because you aren’t printing anything.

A return is used to send information from a function back to were it was called:

def add(n1, n2):
  return n1 + n2

number = add(3, 5)
#          \
#           The return sends 8 back to were the function was called
#           Since it was the value assigned to number, number is now
#           equal to 8

However you don’t see the value unless you display it, most commonly with print().


Thank you for the explanation, got the result with the print command! Sorry for the confusion with the indents! :slight_smile:

1 Like