[Tutor] python strings?

Alan G alan.gauld at freenet.co.uk
Thu Sep 8 21:52:40 CEST 2005

>>     print "The value in years is", principal

> To actually answer your question, in order to print this correctly, 
> you
> need to tell Python to convert the integer (principal) to a string 
> by
> using the built-in function str() like so:

Not so. print automatically calls str() on all its arguments so
the programmer doesn't need to.

An alternative way to solve your probnlem is to use format strings:

print "Years = %s;\tPrincipal = %s" % (years,principal)


Alan G
Author of the Learn to Program web tutor

More information about the Tutor mailing list