6
votes

I'm trying to understand the following Python quine:

s = 's = %r\nprint(s%%s)'
print(s%s)

In particular, I'm having trouble finding any info about that %% part. Anyone know what that does exactly, in this context?

Postscript: Sorry for the silly question - it's just an escape character. My google search was focused on %%, which didn't lead me in the right direction. Thanks to those who took the time to respond! :)

1
Did you try Google? The first few hits for Python string percent sign answer your question. - user2357112 supports Monica
not a dupe, one looking for an explanation of %% doesn't know to look for escaping percents. - Aaron Hall♦

1 Answers

13
votes

%% means a percent symbol after using the % operator on your string.

'%' is a special symbol for substitutions, so when you put

'Hi %s'%name

you are substituting a variable into the string at the point where %s occurs. There are lots of other % codes for different uses. But to just get a percent symbol after substitution, you put %%.