469,610 Members | 2,007 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,610 developers. It's quick & easy.

beigginer: int+string

Hello
I have:
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 ?
Thanx
Michal

Jul 18 '05 #1
3 23252
On Tue, 06 Jul 2004 08:42:18 +0200, vertigo <no**@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)

chris
Jul 18 '05 #2
>On Tue, 06 Jul 2004 08:42:18 +0200, vertigo <no**@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/
Jul 18 '05 #3
Just use

var3=var2+str(var1)

Wai Yip Tung

On Tue, 06 Jul 2004 08:42:18 +0200, vertigo <no**@microsoft.com> wrote:
Hello
I have:
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 ?
Thanx
Michal


Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Ron Adam | last post: by
4 posts views Thread by Stephen Russell | last post: by
reply views Thread by mirkmmd | last post: by
4 posts views Thread by Milan Krejci | last post: by
2 posts views Thread by subramanian100in | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.