Concept behind 8.str()


So according to the exercise 8.str() we define
pi = 3.14

then use str() to print pi
print (str(pi))

and the result is 3.14

I was expecting to see '3.14' since str(pi) converts 3.14 to '3.14'.

Can someone clarify whether my observations are right or wrong?


no, you use ' or " to tell python you are defining a string, but the moment you print this, you won't see them:

print "hello world"

will output:

hello world

it would be a bit weird if you where to ask a user for input, and they would see all those weird quotation marks ("), with a little bit of cheating we can see that your str() does work:

pi = 3.14
print pi
print type(pi)
pi = str(pi)
print pi
print type(pi)

is type() already covered? it returns the data type (float and string in this case), does this make sense?


got it bro.. :smile:


Thank you for your clarification, the lecture makes sense now. No, I have not come across type() yet. I appreciate your response.


Your welcome. Well, type() is pretty straight forward, it returns the data type (str, int)