f = open(filename, "r") whattoReturn = "None" if strToFind in f.read(): whattoReturn = strToFind
Here is what the above code is Doing:
1. It’s opening the file in read mode.
2. It’s reading the contents of the file into a string.
3. It’s checking if the string to find is in the string read from the file.
4. It’s returning the string to find if it’s found, or “None” if it’s not found.