Why use str() instead of quote mark



Its more about a question on why I cant use quotes marks to convert a number into string, rather than use the str() operator. I tried using it and the interpreter gave the same result.
instead of using print "The value of pi is around " + str(3.14)
if I use: print "The value of pi is around "+"3.14"
I get the same results; so whats the difference here? why should I go with str() operator?

print "The value of pi is around "+"3.14"


this exercise is about teaching a concept, which is how to cast to a string. Lets say for whatever reason i need a random integer:

from random import randint

now our random integer is stored in a variable named x. How would you get from integer to string? using str()

so yea, if possible you can just put quotation marks around the number, but this is not always possible


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