Re: Struggling with basics
- From: Duncan Booth <duncan.booth@xxxxxxxxxxxxxxx>
- Date: 25 Sep 2005 18:55:38 GMT
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).
.
- Follow-Ups:
- Re: Struggling with basics
- From: Peter
- Re: Struggling with basics
- References:
- Struggling with basics
- From: Jason
- Struggling with basics
- Prev by Date: Re: Struggling with basics
- Next by Date: Reinhold Birkenfeld [Re: "Re: cElementTree clear semantics"]
- Previous by thread: Re: Struggling with basics
- Next by thread: Re: Struggling with basics
- Index(es):
Relevant Pages
|