Unexpected Python String Quotation Behavior in f-Strings

This is a bit of a curveball for me.

some_letters = "abcdadedf sdqadassaa"
print(f"number of letter m: {some_letters.count("a")}")

I would expect this to throw a syntax error because the quotation marks are nested incorrectly. However, when I run this, it executes without an error.

I am using Python 3.13.3.

Do you know why this is happening? My understanding is that this code should not run successfully given the quotation mark usage.

1 Like

Oo that makes sense thank you so much. Would need to update my knowledge base.