You’re asking whether Python has a built-in way to count '#' characters in a string, and the short answer is yes. I’ll answer directly and point out the exact call you can use in your current code.
Yes. For strings, use the standard method str.count().
In your case:
n_tags = first_line.count('#')
That counts how many # characters appear in first_line.
Two related notes for your snippet:
count() is not a standalone built-in for strings; it’s a method on the string object.
If you only care about leading # (like Markdown heading markers), use: