8

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! :)

Rafael_Espericueta
  • 495
  • 1
  • 6
  • 14

1 Answers1

17

%% 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 %%.

khelwood
  • 55,782
  • 14
  • 81
  • 108