Strings Vs simple addition


I want to understand the point of using str function here , when i can add the number "2" or "3.14" by just putting it under quatations than why should i use str() function.

print "The value of pi is around " + "3.14"
print "i have" + ' 2' + ' Coconuts'
print "i have " + str(2) + ' Coconuts'


well, its not always possible to simply place apostrophes around it. For example retrieving values from database, or a unknown number after a math operation


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.