Search Engine | Sololearn: Learn to code for FREE!


Search Engine

Hey guys, can anyone tell me why it prints None after the answer in my code? def search(x, y): x = x.split() if y in x: print("Word found") else: print("Word not found") text = input() word = input() print(search(text, word)) I am new here and I am trying to learn the basics (meaning: I am failing to learn them😅)

4/26/2021 6:37:59 PM

Elena Vitsiou

6 Answers

New Answer


Ярослав Вернигора(Yaroslav Vernigora) is correct that with the print statement within the function is sufficient. the reason you are seeing None is most likely because you have no return line within the function. for you to get the result of a function you are calling you need to end the function with a return line with the results you want returned. an example would be like: def function(x): answer = x*2 return answer result = function(2) print(result) #4 if i didnt have the return line, it would print None, because i didnt return anything when i called the function. i hope that makes sense.


Hi! you don't need to call the print function and insert your function there. your function is already self-sufficient. just call it at the end of the program 😉


Thank you all!


This should work... text = input() word = input() def search(): if word in text: return "Word found" else: return "Word not found" print(search())


Change the last line by removing the print statement. That's why you are getting None.


I think that in our case, the return is not necessary, because we do not output any values, we just print two phrases, depending on the condition. Wow! Is that a lot of words you just typed yourself? 😲