0
search engine challenge
Hey, help me out pls. I know that this way of solving is overcomplicated, but i wonder why this code not working? if you run it, it will additoinally print "None" on the new line. And i dont get were from it appeared? def search(text, word): if text.count(word) >=1: return(print("Word found")) else: return(print("Word not found")) text = input() word = input() print(search(text, word))
4 Respostas
+ 2
Вячеслав Ершов you had two outputs in your program:
1. The print in the search function (if or else branch)
2. The print on your last line where you call search function
The first prints the desired output.
The second prints the value that your search function returns. You are returning the return value of print. But print has no defined return value, so its return value is None, so the second print outputs "None"
+ 1
Thanks, that worked. But I still do not understand why it print 'none'
0
The print function generates output and doesn't return anything, so its return value is None. Your search function returns that None value and the last line prints it
0
Thanks a lot