What does %%(%s)s mean/expand to in Python? What does rowshtml += (rowhtml % ((fieldname, ) * 3)) expand to? Kindly explain.

Christian Gollwitzer auriocus at gmx.de
Wed Oct 29 09:13:29 CET 2014


Am 29.10.14 07:15, schrieb satishmlmlml at gmail.com:
> What does %%(%s)s mean in Python?

Instead of posting all those questions here, you can simply try it in an 
interactive python interpreter:

Apfelkiste:VecTcl chris$ python
Python 2.7.2 (default, Oct 11 2012, 20:14:37)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> test='%%(%s)s'
 >>> test % 'foo'
'%(foo)s'
 >>>

> also
> what does
> rowshtml += (rowhtml % ((fieldname,) * 3)) expand to?
>
 >>> fieldname='foo'
 >>> (fieldname,)*3
('foo', 'foo', 'foo')
 >>> test='first %s second %s third %s'
 >>> test % ((fieldname,)*3)
'first foo second foo third foo'
 >>>

	Christian



More information about the Python-list mailing list