Struggling with basics

Peter peter at commonlawgov.org
Sun Sep 25 17:16:22 EDT 2005


Duncan Booth wrote:

>Jason wrote:
>
>  
>
>>My first problem (lack of understanding of course) is that if I run the 
>>above, I get an error saying:
>>
>>     print "%s - %s" % name,score
>>TypeError: not enough arguments for format string
>>
>>Now I understand what it's saying, but I don't understand why.
>>
>>    
>>
>
>The problem is precedence.
>
>      print "%s - %s" % name,score
>
>is equivalent to:
>
>      print ("%s - %s" % name),score
>
>not:
>
>      print "%s - %s" % (name,score)
>
>The % operator binds more tightly than the comma, so you need to put 
>parentheses around the argument to % (as in the last line above).
>  
>
Well said. :)

- Peter



More information about the Python-list mailing list