Can someone clarify please?


#1



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

Sorry, but what is the point of converting pi into a string? Won't print(pi) give the exact same result as print(str(pi))


#2

There is a difference.

suppose..

x = "3" #x is a string here
y  = 3   # y is a number here

#when you do this..

print x # it will print 3
print y #it will print 3

so it means that both are Equal?
No.
when print acts on string values ,It omits the quotes and just prints it.

when we do this..

x = 3
x = str(3)

then it means that we're making 3 a string.
Its no more a number but a string"3".
so str() converts a number 3 (int value) into a string value "3"


#3

Hey there thank you for the quick reply. So basically, in your case, on paper, print will produce the same result for x and y. But in actual fact, they are of different variable types?


#4

Yup! print is just for representation.
and both (x,y) are still different data types.


#5

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