次のコードがあります
test = "have it break."
selectiveEscape = "Print percent % in sentence and not %s" % test
print(selectiveEscape)
出力を取得したいと思います:
Print percent % in sentence and not have it break.
実際に起こること:
selectiveEscape = "Use percent % in sentence and not %s" % test
TypeError: %d format: a number is required, not str
% i手段「整数の小数表現、スペースで左パディング。
\%それは実際にエスケープさ\\%れます。 <escape><escape>私が見た典型的なパターン\であり、良くも悪くも、最も一般的なエスケープ文字です。
\ 、印刷しなければならなかった場合、どうやってエスケープします\\%か?特殊文字も状況に応じて特殊でない場合は、特殊文字の繰り返しによるエスケープが必要になります。
\%?それは私の推測でした、%%代わりにそれを見つけて驚いています-かなり直観に反するようです。