Python: What Does The Two % Signs In Print '%r K%%k'%'a' Do?
I came across this while researching quines. I am curious to know what %% does in the following print '%r k%%k'%'a' I understand that %r takes the string representation of the argu
Solution 1:
%%
is the escape for a single %
character; you could not otherwise use that character:
>>> '%s: %%' % 'One percent character'
'One percent character: %'
See the String Formatting Operations documention:
%
No argument is converted, results in a'%'
character in the result.
By removing one %
character, you formed the %k
format, but there is no conversion type k
. The error message reflects that:
>>> '%k' % 'No such format type'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: unsupported format character 'k' (0x6b) at index 1
Post a Comment for "Python: What Does The Two % Signs In Print '%r K%%k'%'a' Do?"