how does the % work?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sat Mar 23 19:53:00 EDT 2013


On Sat, 23 Mar 2013 09:57:48 -0600, Michael Torrie wrote:

> On 03/23/2013 01:38 AM, Steven D'Aprano wrote:
>> Just to add confusion, the two lines are exactly the same in Python 2,
>> where Print is not a function!
> 
> Perhaps this is a good reason use the slightly more complicated but
> easier to get right format method.
> 
> print ("{0}, {1}, {2}".format(1,2,3))


Misplaced parentheses are possible either way.

print ("{0}, {1}, {2}".format(1,2,3))
print ("{0}, {1}, {2}").format(1,2,3)


> And it's worth noting that using the string formatter or the old %
> operator on a string works anywhere where there're strings, not just in
> the print function.


Very true.



-- 
Steven



More information about the Python-list mailing list