beigginer: int+string

Andrew McNamara andrewm at object-craft.com.au
Tue Jul 6 03:03:36 EDT 2004


>On Tue, 06 Jul 2004 08:42:18 +0200, vertigo <none at microsoft.com> wrote:
>> var1=0
>> var2="text"
>> var1=var1+2
>> 
>> var3=var2+var1 ???
>> i want to receive "text2" in var3, but i receive error can not add int 
>> to string. How can i do it ?
>
>As the error message tells you, you can only add two variables of the
>same type. Thus you need to change var1 to a string representation. One
>way of doing this is:
>
>var3 = var2 + str(var1)

He should also look at the Python Library Reference, specifically the page
on string formatting operations:

    http://docs.python.org/lib/typesseq-strings.html

-- 
Andrew McNamara, Senior Developer, Object Craft
http://www.object-craft.com.au/



More information about the Python-list mailing list