2

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

example = "%%(test)%" % {'test':'name',}
print example

目的の出力は「%name%」です

ありがとう

4

2 に答える 2

7

別の方法は、新しいAdvanced String Formattingを使用することです

>>> example = "%{test}%".format(test="name")
>>> print example
%name%
于 2009-10-27T10:19:23.390 に答える
5
example = "%%%(test)s%%" % {'test':'name',}
print example

%(key)sで識別される文字列のプレースホルダーですkey。演算子を使用すると%%エスケープします。%%

于 2009-10-27T10:00:27.390 に答える