faqts : Computers : Programming : Languages : Python : Common Problems : Strings

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

21 of 22 people (95%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

How do I get Python to force 'a' and 'b' into strings so that a + ":" + b concatenates instead of trying to add?

May 19th, 2000 00:53
unknown unknown, Andy Lester, Remco Gerlich, Martijn Faassen, Scott


The str() function.

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

Or use the % operator, of course.

str = "%d:%d" % (a,b)