I have the below code
Test1 = Price[Product.index(TestABC)]+ AddQTYPriceA
print Test1
print "try this test" + Test1
When it needs to print Test 1 it gives the correct answer. I want to try and add text to the front of it and so I have entered print “try this test” + Test1
For the second print command it gives the following error.
Traceback (most recent call last):
File "C:\Python26\data.py", line 78, in <module>
print "try this test" + Test1
TypeError: cannot concatenate 'str' and 'float' objects
Can someone assist how I can get text to appear at the front.
Greggy D
In order to concatenate the string and float you need to cast the float as a string using the
str()function.Or you could use the
.format()string method:Both of these methods are documented on the python string built-in type page.