質問

次のコードをどのように機能させますか?

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 で識別される文字列のプレースホルダーです。 演算子を使用すると、 %% をエスケープします。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top