How to recast integer to a string

Larry Bates larry.bates at websafe.com
Tue May 9 21:42:14 CEST 2006


James wrote:
> How to recast an integer to a string?
> 
> something like
> n = 5
> str = str + char(n)
> 
> 
> J.L
> 
Two items:

1) Never use 'str' as a variable name as it will
shadow the built in str function.  If you do, this
WILL jump up and bite you.

2) Either s=str(n) or s="%i" % n will return string
containing '5' (without the quotes of course).

Note: chr(n) would return character whose ASCII decimal
value is 5 (ASCII ENQ).

-Larry Bates



More information about the Python-list mailing list