Is there a built-in fuction can convert any type of variable to string?

Steve Holden sholden at holdenweb.com
Fri Jan 25 12:59:07 EST 2002


"Ricky" <store_li at sina.com> wrote ...
> I look around python reference guide, but can't find a function which can
> convert any type of variable to string type?
>
> Is there any one or not?
>
Well, the closest you'll come is str(). You can also use repr(), whose
result generally tries to be Python code, though this only works up to a
point.

>>> str(m.group(0))
'steve.holden at holdenweb.com'
>>> str(m)
'<SRE_Match object at 014B92D0>'
>>>

Note that here the interactive interpreter is using repr(), which is why it
puts the quotes around the strings. If you used print instead there wouldn't
be any quotes.

regards
 Steve
--
Consulting, training, speaking: http://www.holdenweb.com/
Python Web Programming: http://pydish.holdenweb.com/pwp/








More information about the Python-list mailing list