A flag is just a variable that holds (and is tested) for a single condition. Like in your case you want to know if a word is found in a file. So your flag might be:
Before you start on the file, you haven't found anything yet, so you'll set the variable to false.
If the flag is false, you never found anything and you can do your "no match found" processing.
match_found
.Before you start on the file, you haven't found anything yet, so you'll set the variable to false.
match_found = FalseAs you work on the file, you'll discard any lines that don't match. They won't matter. But if you do find a matching line, you'll print it out, and you'll also change the flag. If you find the line 20 times in the file, you'll set the flag 20 times. But that doesn't matter.
match_found = TrueAfter you're done with the file, you now have an indicator as to whether or not you found anything. If you did, the flag is set to true and you go to the next file.
If the flag is false, you never found anything and you can do your "no match found" processing.
if match_found: pass # don't need to print anything else if it's found? else: print("No match in this file.")