对于mo在f字符串中包含注释将很有用。例如,使用以下代码:
f"""
<a
href="{ url }"
target="_blank" { # users expect link to open in new tab }
>bla</a>
"""
如果此代码等效于:
f"""
<a
href="{ url }"
target="_blank"
>bla</a>
"""
您可以在大括号之间包含完整的Python表达式,但看起来似乎无法包含注释。我对么?有没有办法做到这一点?
From PEP498:
There is no way to comment other than putting a
'#'
character in Python, so it is not possible.