Struggling with basics

Duncan Booth duncan.booth at invalid.invalid
Sun Sep 25 14:55:38 EDT 2005


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).



More information about the Python-list mailing list