+ 1

How to check a word in string in python 3

..

25th Dec 2018, 3:39 PM
Karthik Devillers
Karthik Devillers - avatar
15 odpowiedzi
+ 7
word = input("Enter word to find:") string = input("Enter string: ") if word in string: print("Word is in string")
25th Dec 2018, 3:57 PM
Lambda_Driver
Lambda_Driver - avatar
+ 7
Hmmmm. That will work if the string is separated by a space. What if it's not separated by a space?
25th Dec 2018, 4:17 PM
Lambda_Driver
Lambda_Driver - avatar
+ 7
Out of curiosity, may I see your code? I may have misinterpreted something. This is what I thought you were trying to do. https://code.sololearn.com/c7sRxYYE7t8H/?ref=app
25th Dec 2018, 4:27 PM
Lambda_Driver
Lambda_Driver - avatar
+ 3
word = "hello" string = "hello world" if word in string: print("Word is in string")
25th Dec 2018, 3:42 PM
Paul Grasser
Paul Grasser - avatar
+ 1
It has to check the hello world string by word
25th Dec 2018, 3:44 PM
Karthik Devillers
Karthik Devillers - avatar
+ 1
word = "hello" string = input("Enter string: ") if word in string: print("Word is in string")
25th Dec 2018, 3:44 PM
Paul Grasser
Paul Grasser - avatar
0
If the input is given by user
25th Dec 2018, 3:43 PM
Karthik Devillers
Karthik Devillers - avatar
0
Try the code
25th Dec 2018, 3:44 PM
Paul Grasser
Paul Grasser - avatar
0
It will work but
25th Dec 2018, 3:51 PM
Karthik Devillers
Karthik Devillers - avatar
0
It will work but the user is going to give input he won't give hard coded values
25th Dec 2018, 3:52 PM
Karthik Devillers
Karthik Devillers - avatar
0
I had finded answer
25th Dec 2018, 4:01 PM
Karthik Devillers
Karthik Devillers - avatar
0
N= input().split(" ") By this statement we can separate a word from string
25th Dec 2018, 4:02 PM
Karthik Devillers
Karthik Devillers - avatar
0
If the string is not separated means how its said to be a word
25th Dec 2018, 4:19 PM
Karthik Devillers
Karthik Devillers - avatar
0
Of course yours also correct
25th Dec 2018, 4:28 PM
Karthik Devillers
Karthik Devillers - avatar
0
But wait for mine in will send now
25th Dec 2018, 4:28 PM
Karthik Devillers
Karthik Devillers - avatar