[Tutor] How to substitute an element of a list as a pattern forre.compile()

Kent Johnson kent37 at tds.net
Sat Jan 1 22:25:24 CET 2005


Jacob S. wrote:
> Rich needs to
> make the % formatting "%d"%x   instead of  "%s"%x  because he showed that x
> is an integer not a string.

Actually %s formatting is very flexible and forgiving, it outputs str(x) whatever x is. For example:
  >>> for x in ['string', 10, True, [1,2,3] ]:
  ...   print '%s' %x
  ...
string
10
True
[1, 2, 3]

Kent


More information about the Tutor mailing list