[Python] To search for specific characters in a string

Asked 2 years ago, Updated 2 years ago, 29 views

infile=open("python_07_05.txt",'w')

words=input()
word=input()
if word in words:
    infile.write("find word :"+word)

infile.close()

outfile=open("python_07_05.txt",'r')
text=outfile.read()
print(text)
outfile.close()

I'm going to write a code that prints out the words I want to find when I enter the data in words, and prints out nothing if I want to find, and if I don't, I'm going to print out nothing.

Please give me some advice on how to code. Thank you.

python python3

2022-09-22 19:15

1 Answers

if word in words.split(): infile.write("find word :",word)

If I do this, it doesn't print out at all crying if words.find(word): infile.write("find word : "+word) Question number 2 has been solved, but question number 1 has not been solved. <

That's weird It can't be done because it's divided into words and put them in an array.

word = "you"
words = "you're good at"

if word in words.split():
    print(word)

I think you can examine it with.


2022-09-22 19:15

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.