How to find a string in a file in Python

Finding a string in a file checks whether the string is contained within the contents of the file.

Solution for How to find a string in a file in Python : You can use file.read() to find a string in a file Call open(pathname, mode) with the file name as pathname and “r” as mode to return a file object that has been opened for reading. Call file.read() to return the contents of file as a string. Use the in keyword to check if the desired string is in the contents.


how-to-find-a-string-in-a-file-in-python