Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is %% for in Python? [duplicate]

Tags:

python

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

like image 232
Rafael_Espericueta Avatar asked Sep 17 '14 23:09

Rafael_Espericueta


People also ask

What is duplicated () in Python?

The duplicated() method returns a Series with True and False values that describe which rows in the DataFrame are duplicated and not. Use the subset parameter to specify if any columns should not be considered when looking for duplicates.

How do you duplicate items in Python?

In Python, we use = operator to create a copy of an object. You may think that this creates a new object; it doesn't. It only creates a new variable that shares the reference of the original object.


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

like image 144
khelwood Avatar answered Sep 18 '22 14:09

khelwood