I can't get to include quotation marks in the following string interpolator:

f"foo ${math.abs(-0.9876f)*100}%1.1f%%"

The output is

foo 98.8%

Now the desired output is

foo "98.8%"

Inserting \" doesn't work, only produces "unclosed string literal" errors.

有帮助吗?

解决方案

Seems that this problem wouldn't be fixed. You can use one of the following workarounds:

  1. multi-line strings:

    f"""foo "${math.abs(-0.9876f)*100}%1.1f%""""

  2. \042:

    f"foo \042${math.abs(-0.9876f)*100}%1.1f%\042"

  3. ${'"'}:

    f"foo ${'"'}${math.abs(-0.9876f)*100}%1.1f%${'"'}"

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top