[Tutor] what does %s do?
Fri, 26 Jan 2001 16:15:38 +0800
Okey dokey... with string manipulation comes the use of %. This prefixes
other letters, such as in %s (which by the way is short for string). It
replaces the %s in the string with whatever follows the % following the
string. So with a string '%sbuffer' % ('one'), the resulting string will
be 'onebuffer'. So it goes through a, which I assume is a list of
strings: ['one','two','three']. It goes through and executes the string
'onebuffer = ', 'twobuffer = ', 'threebuffer = '.
I can't give you information on all the string substitution prefixes,
sorry, I'm not at one with my Python documentation.
Hope you can understand my odd way of thinking...
> -----Original Message-----
> From: firstname.lastname@example.org
> [mailto:email@example.com]On Behalf Of
> Sent: Friday, 26 January 2001 2:26
> To: firstname.lastname@example.org
> Subject: [Tutor] what does %s do?
> >hi tutors.
> I 've been going through some code sent here from arcege
> (thanks arcege) -
> it works great, but I wonder what %s does??
> the code:
> >>> a = [ 'one', 'two', 'three' ]
> >>> dir()
> ['__builtins__', '__doc__', '__name__', 'a']
> >>> for b in a:
> ... exec '%sbuffer = ' % b #here it is
> >>> dir()
> ['__builtins__', '__doc__', '__name__', 'a', 'b', 'onebuffer',
> 'threebuffer', 'twobuffer']
> as usual, thanks for the help
> m baker
> Tutor maillist - Tutor@python.org