Python - Find line number from text file [closed]
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . I'm writing a code that looks in a text file, and sees if the input is in there. e.g. I input "pizza" My textfile contains: bread pizza pasta tomato I want to find a way to print the the line number the word pizza is on. Any help? 回答1: with open('test.txt') as f: content = f