[Tutor] How do I display a changing thing in text?

Hugo González Monteverde hugonz-lists at h-lab.net
Tue Nov 15 05:05:06 CET 2005

The interactive intepreter is you friend. Of course I'm using actual 
numbers instead of variables for the examples. Let's see

IDLE 1.0.3
 >>> "Computer = %1.0d Player = %1.0d" (1,2)

Traceback (most recent call last):
   File "<pyshell#0>", line 1, in -toplevel-
     "Computer = %1.0d Player = %1.0d" (1,2)
TypeError: 'str' object is not callable

HMMMM what is the problem?

 >>> "Computer = %1.0d Player = %1.0d"%(1,2)
'Computer = 1 Player = 2'

Here you go. You were missing the % sign after the string, with in this 
case is the operator...

Nathan Pinno wrote:
> Hugo and all,
> So in order to write what I wanted the correct code would be:
> "Computer = %1.0d Player = %1.0d" (a,b)
> Am I correct or is this wrong?
> Nathan Pinno 
> -----Original Message-----
> From: Hugo González Monteverde [mailto:hugonz-lists at h-lab.net] 
> Sent: November 14, 2005 8:27 PM
> To: Nathan Pinno
> Cc: Tutor mailing list
> Subject: Re: [Tutor] How do I display a changing thing in text?
> Hi Nathan,
> Take a look at string interpolation in the tutorial. I don't know what
> method you're following for learning Python, but I've found the 'official'
> tutorial a great resource, even when you already know Python,
> http://docs.python.org/tut/node9.html#SECTION009100000000000000000
> Nathan Pinno wrote:
>>How do I display a changing thing (i.e.. the score of the game) in text? 
>>I think it has something to do with this key: %, but I forget how to 
>>do it. Can someone show me how to do it again?
>>Nathan Pinno
>>Tutor maillist  -  Tutor at python.org

More information about the Tutor mailing list