What is a string and why should i convert non string into string


"""Declare and assign your variable on line 4,
then call your method on line 5!"""

4.pi = 3.14
5.print str(pi)

o/p - 3.14

But when i just use print pi it give the output 3.14, then why should i use print str(pi) and convernt non-string into string


string can be many things, pieces of text or numbers stored a strings, at this point you must created a string:

test = "I am a string"

anyway, the conversion in this case is a bit pointless, but if you for example want:

pi = 3.14
print "the number pi is: " + str(pi)

you need str() otherwise python will throw you an error (trying to join a string and a float)


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