integer to ascii

Jeff Shannon jeff at ccvcorp.com
Wed Nov 7 19:41:18 EST 2001


Max M wrote:

> "harry" <hartanto at telusplanet.net> wrote in message
> news:VX7G7.18181$5e2.4403261 at news1.telusplanet.net...
>
> > instead of '5' as the output, how do i make the output as '23' -> string
> > concatnation instead of integer.
>
> There are a few ways of doing it:
>
> rows = `2`
> ( or rows = '%d' % 2 )
> columns = str(3)
> joined = rows + columns
>
> or
>
> rows = 2
> columns = 3
> joined = `rows` + str(columns)
>
> all depending on how you want to use you variables afterwards.

Or:

rows = 2
columns = 3
joined = "%d%d" % (rows,columns)

String formatting is your friend.  It is *much* faster than concatenation with
+, too (though this won't show up unless you're doing it in a tight loop...)

Jeff Shannon
Technician/Programmer
Credit International





More information about the Python-list mailing list