Strings Vs simple addition


#1



https://www.codecademy.com/courses/python-beginner-sRXwR/3/2?curriculum_id=4f89dab3d788890003000096


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'


#2

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


#3

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