When you use match and search methods of module re, if there is a match, it has bool value of True and if there is no match, you get None that has a bool value of False.
Match objects are always true, and None is returned if there is no match
>>> bool(re.search("def", "abcdefgh")) True >>> bool(re.search("rest", "pqrstuv")) False