% sign in python?

Roy H. Han starsareblueandfaraway at gmail.com
Thu Jul 17 16:41:22 CEST 2008


The percent sign is a placeholder.

For example, if
level = 1
msg = 'look'

Then
'[[Log level %d: %s]]' % ( level, msg )
becomes
'[[Log level 1: look]]'

%d means insert an integer
%s means insert a string

You can also use dictionaries.
d = {'string1': 'hey', 'string2': 'you'}
Then
'%(string1)s %(string2)s' % d
becomes 'hey you'


On Thu, Jul 17, 2008 at 10:33 AM, korean_dave <davidreynon at gmail.com> wrote:
> What does this operator do? Specifically in this context
>
> test.log( "[[Log level %d: %s]]" % ( level, msg ), description )
>
> (Tried googling and searching, but the "%" gets interpreted as an
> operation and distorts the search results)
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list