What is %% for in Python?

Question:

I’m trying to understand the following Python quine:

s = 's = %rnprint(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! 🙂

Asked By: Rafael_Espericueta

||

Answers:

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

Answered By: khelwood
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.