print syntax

Bernie editor at pythonrag.org
Sat Sep 5 09:32:05 CEST 2009


On Thu, 03 Sep 2009 12:22:14 -0400, doug wrote:

> I am new to python, working by way through 'Core Python Programming'. I
> can find no description of using print with the built-in type for
> formatting. I think I have got some [most?] of it from Chun, google, and
> python.org. My comment is - it should not be that hard to find. I would
> suggest a link from the print syntax section.
> 
> What is seems to be is:
> 
>    print "format-spec" % (variable-list)
> 
> I assume the '%' is required token.
> 
> 
> 
> _____
> Douglas Denault
> http://www.safeport.com
> doug at safeport.com
> Voice: 301-217-9220
>    Fax: 301-217-9277


You say "using print with the built-in type for formatting." - It's two 
separate things, print just prints a string.  You can use the formatting 
quite separately on the string first.

my_string = "%s %s %s" % (1, 2, 3)    # creates string "1 2 3"
print my_string

so you probably would find difficulty is searching for 'print 
formatting', you should be looking for string formatting.
       



More information about the Python-list mailing list