print syntax

Robert Kern robert.kern at gmail.com
Thu Sep 3 12:54:06 EDT 2009


On 2009-09-03 11:50 AM, Benjamin Kaplan wrote:
> On Thu, Sep 3, 2009 at 12:22 PM,<doug at safeport.com>  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.
>
> The % has absolutely nothing to do with the print statement. The (old)
> formatting syntax is based on the C printf syntax but it's actually
> the modulo operator on a string, not a piece of the print statement.
> The documentation for it is in the documentation for strings.

Namely:

http://docs.python.org/library/stdtypes.html#string-formatting

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco




More information about the Python-list mailing list