Doing tutorial - my script shows different results.

Jere Kahanpaa jkahanpa at
Thu Sep 21 14:23:00 CEST 2000

vbMark <vbmark at> wrote:
: Greetings,
: The script in the tutorial (7.1 Fancier Output Formatting) is:
:>>> def go():
: 	import string
: 	for x in range(1,~11):
: 		print string.rjust('x',2),string.rjust('x*x',3),
: 		print string.rjust('x*x*x',4)

Well, I haven't checked the new tutorial but I'd bet it 
doesn't say exactly that. In python ' and ` are different 
characters with a very different role: 

x = 1   # Define a variable
'x*x' # Is a string "x*x"
`x*x` # multiply x with itself and then convert the RESULT 
      # To a string

This version should work:

>>> def go():
       import string
       for x in range(1,11):
               print string.rjust(`x`,2),string.rjust(`x*x`,3),
               print string.rjust(`x*x*x`,4)                                 

Jere Kahanpää
jere.kahanpaa at
                               NO ONE CAN RESIST
                               the toe TAPPIN', hand CLAPPIN',
                               exoskeleton SNAPPIN' SATISFACTION
                               of Entomophagy. HEY! What are you waiting
                               for? GET YER OWN BUG! 

More information about the Python-list mailing list