beigginer: int+string

V

vertigo

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
 
C

Chris Share

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top