Python文字列フォーマット特殊文字
-
06-07-2019 - |
質問
次のコードをどのように機能させますか?
example = "%%(test)%" % {'test':'name',}
print example
目的の出力が"%name%"である場合
ありがとう
解決
別の方法は、新しい高度な文字列フォーマット
>>> example = "%{test}%".format(test="name")
>>> print example
%name%
他のヒント
example = "%%%(test)s%%" % {'test':'name',}
print example
%(key)s
は、 key
で識別される文字列のプレースホルダーです。 %
演算子を使用すると、 %%
は%
をエスケープします。
所属していません StackOverflow