[Tutor] python strings?
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,
> need to tell Python to convert the integer (principal) to a string
> 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)
Author of the Learn to Program web tutor
More information about the Tutor