on-internet
← Community

Is there a way to include a comment in an f-string?

Stack Overflow ·

It would be useful for me to include a comment in an f-string. For instance, take this code: f""" <a href="{ escape(url) }" target="_blank" { # users expect link to open in new tab } >bla</a> """ It would be nice if this code was equivalent to: f""" <a href="{ escape(url) }" target="_blank" >bla</a> """ You can include full Python expressions in between the curly braces, but it looks like you can't include comments. Am I correct? Is there a way to do this?

Comments

Sign in or sign up to comment and upvote.

No comments yet.