Forcing type conversion

Remco Gerlich scarblac-spamtrap at pino.selwerd.nl
Wed May 17 10:28:34 EDT 2000


Dale Strickland-Clark wrote in comp.lang.python:
> How do I get Python to force 'a' and 'b' into strings so that the following
> concatenates instead of trying to add.
> 
> a = 1
> b = 2
> a + ":" + b

The str() function.

a = 1
b = 2
str(a) + ":" + str(b)

Or use the % operator, of course.

-- 
Remco Gerlich,  scarblac at pino.selwerd.nl

   This is no way to be
     Man ought to be free      -- Ted Bundy
       That man should be me



More information about the Python-list mailing list