Mohamed Ashraf Mohamed Ashraf - 1 year ago 73
Python Question

How can I add two variable and assign to result variable in Python?

I am very new to python world,Please help me how to concatenate str and int objects.

a = 100
b= 200
c = 'Result ='
print (c + a + b)

Throwing error

>>> print (c + a + b)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot concatenate 'str' and 'int' objects

I looking output as, Result = 300

Thank in advance...!!!

Answer Source
a = 100
b = 200
c = 'Result = '
print (c + str(int(a + b)))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download