I am self-studying Python 3 on Sololearn course. And I am now learning regular expression.
Here is the source code:
import re
pattern = r"spam"
if re.match(pattern, "spamspamspam"):
print("Match")
else:
print("No match")
--- according to Sololearn Python 3 Tutorial Course ---
The condition in if statement is quite confusing me. To my knowlegde I have gained, the condition in if statement should be in boolean expression. However, the re.match function, determines whether it matches the beginning of a string, does not return boolean value (If it matches, the function returns an object representing the match. If not, it returns None).
Therefore, I do not quite understand the if statement of the above code? Can anyone give me some explanations?