0
I have a problem in python Search engine
It outputs needed output and None as well.How to stop outputting None?
9 Antworten
+ 5
Hasara Pramuditha Herath
Your code:
text = input()
word = input()
def search (text,word):
if word in text:
print ("Word found")
else :
print ("Word not found")
print(search(text, word))
By using the `return` statement instead of `print` within the `search` function, the function will return the desired string instead of `None`.
+ 7
Return value inside function then print function
Or
Print value inside function and just call that function
+ 5
Sakshi ,
it is not seen as very helpful when we are going to post a ready-made code, as long as the op has not shown his attempt here.
it is more helpful to give hints and tips, so that the op has a chance to find a solution by himself.
+ 5
Sakshi ,
ok - sorry, i understand!
+ 4
Lothar I'm sorry, you misunderstood, bro. I didn't provide any code myself. The user provided the code and then deleted it later.
+ 2
Share your attempt
+ 2
Lothar It's ok bro, don't be sorry
+ 1
Sakshi # may I ask you a doubt, is there any difference between these two codes :
def func():
print("hello world")
func()
def funct():
return "hello world"
print(funct())
#both are same, right ? so what is the real use of return ?
0
Both are different, in the first code, this defines a function named func that prints "hello world" when called. By executing func(), the function is called and the output "hello world"
While in the other code, this defines a function named funct that returns the string "hello world" when called. By executing print(funct()).
The real use of the return statement is to pass a value back to the caller of the function.