سؤال

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