Forcing type conversion

Martijn Faassen m.faassen at vet.uu.nl
Wed May 17 10:26:23 EDT 2000


Dale Strickland-Clark <dale at out-think.nospamco.uk> wrote:
> 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

Use the builtin function str():

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

The library reference is your friend. :)

Regards,

Martijn
-- 
History of the 20th Century: WW1, WW2, WW3?
No, WWW -- Could we be going in the right direction?



More information about the Python-list mailing list