0

Why return on search engine challenge

Reveals answer!!! Don't read if don't wanna know!!!! Was stuck on this for a while, had print("") instead of return("") and code wasn't working so obviously changed to return("") and..It works!! Which is great, My question is, why does this work with return and not print? Glad it works it works but want to understand why. text = input() word = input() def search(): if word in text: return("Word found") # had print here else: return("Word not found") #had print here print(search())

10th Sep 2021, 11:48 AM
Trevor Rickard
Trevor Rickard - avatar
2 odpowiedzi
+ 3
def foo(): print("hi") print(foo()) It would print "hi" and then None, because you have a print inside another print. The same in your code. You can change it back to print inside the function, but remove the print where you called the function.
10th Sep 2021, 11:52 AM
Yahel
Yahel - avatar