[Tutor] what does %s do?

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Thu, 25 Jan 2001 23:15:17 -0800 (PST)

On Thu, 25 Jan 2001 michaelbaker@operamail.com wrote:

> I 've been going through some code sent here from arcege (thanks arcege) - 
> it works great, but I wonder what %s does??

Ah!  This is string interpolation, and it does have a peculiar syntax.  
Let's take a look at the line:

> ...   exec '%sbuffer = []' % b   #here it is

The part we're interested in is:

    '%sbuffer = []' % b

What this tells Python is that we want to insert 'b' into our string, and
we tell where to place it in with the special marker '%s'.  %s stands for
string substitution, and there are different kinds of markers, or "format
specifiers" available.  They're explained more in the "Fancier Input
Output" section on the Python Tutorial:


although I'm surprised that it's not more prominently displayed.

Hope this helps!