Strings


#1

We use str() to convert a non string into a string .But i want to when do we convert a non string into a string .


#2

Strings cannot be used in arithmetic.

"3" + 3  =>  '33'

same as,

"3" + str(3)

When formatting string output…

print "3%s" % 3

may result in an error since we are telling the expression to expect a string and instead gave it a number.

print "3%s" % str(3)

will convert to a string before insertion.

We could probably drum up other examples but I suspect you may have already gone down this path, by now?


#3

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