title: what data type is returned by re.search(pattern, stringOfText) in Python? An int or string?
body: <p>Consider the following code below. I was told that if regExMagic() doesn't find a match for Lucy in the string of text, it returns &quot;None&quot; to regExMagic(). Since &quot;None&quot; is already a string why do we still need to wrap regExMagic() in a str() in the comparison below?</p>
  <p>What's interesting is when I removed str() it executed only the else statement (not seen here) for each line (image below) and it didn't throw any TypeError exception that I'm trying to compare 2 different types assuming an int could have been returned to regExMagic(). But since only the else got executed then it probably didn't even bother throwing an exception?</p>
  <p>So my main question is why do we need to include str() in this case even though &quot;None&quot; gets returned as I was told to regExMagic()?</p>
  <p>Am I missing something here?</p>
  <pre><code>import re
  
  def regExMagic(pattern, string):
      objectMatch = re.search(pattern, string)
      return objectMatch
  
  def readingLinesWithRegEx():
  
      try:
          with open('people.txt') as file_object:
              contents = file_object.readlines()
  
              for line in contents:
                  pattern = 'HEllo$'
  
                  if str(regExMagic(pattern, line)) == &quot;None&quot;:
                      print(line)
  </code></pre>