I have the following code
test = "have it break."
selectiveEscape = "Print percent % in sentence and not %s" % test
print(selectiveEscape)
I would like to get the output:
Print percent % in sentence and not have it break.
What actually happens:
selectiveEscape = "Use percent % in sentence and not %s" % test
TypeError: %d format: a number is required, not str
\%? That was my guess, I'm surprised to find it's%%instead - seems pretty counterintuitive. - Demis% imeans "a decimal representation of an integer, padded left with spaces. - Antti Haapala\%it would actually be\\%when written in ordinary code.<escape><escape>is the typical pattern I've seen, and\happens to be the most common escape character, for better or worse. - shemnon\if you had to print\\%? You are bound to require escaping through repetition of special characters, if the special characters are also not special depending on circumstances. - Sassa NF