0

I have a problem in python Search engine

It outputs needed output and None as well.How to stop outputting None?

2nd Jul 2023, 9:28 AM
Hasara Pramuditha Herath
Hasara Pramuditha Herath - avatar
9 Réponses
+ 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`.
2nd Jul 2023, 9:43 AM
Sakshi [Offline 🙃]
Sakshi [Offline 🙃] - avatar
+ 7
Return value inside function then print function Or Print value inside function and just call that function
2nd Jul 2023, 9:32 AM
A͢J
A͢J - avatar
+ 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.
2nd Jul 2023, 10:19 AM
Lothar
Lothar - avatar
+ 5
Sakshi , ok - sorry, i understand!
2nd Jul 2023, 1:35 PM
Lothar
Lothar - avatar
+ 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.
2nd Jul 2023, 11:35 AM
Sakshi [Offline 🙃]
Sakshi [Offline 🙃] - avatar
+ 2
Share your attempt
2nd Jul 2023, 9:31 AM
Sakshi [Offline 🙃]
Sakshi [Offline 🙃] - avatar
+ 2
Lothar It's ok bro, don't be sorry
2nd Jul 2023, 2:49 PM
Sakshi [Offline 🙃]
Sakshi [Offline 🙃] - avatar
+ 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 ?
3rd Jul 2023, 1:10 PM
Navaneeth
Navaneeth - avatar
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.
3rd Jul 2023, 2:09 PM
Sakshi [Offline 🙃]
Sakshi [Offline 🙃] - avatar