how to coerce to a string in Python?

Tim Chase python.list at tim.thechases.com
Tue Apr 28 15:26:00 EDT 2009


Mark Tarver wrote:
> On 28 Apr, 19:58, Mark Tarver <dr.mtar... at ukonline.co.uk> wrote:
>> How do you coerce an object to a string in Python?
>>
>> 123 --> "1 2 3"
>> [1,2,3] -> "[1,2,3]" etc
> 
> Ah , 'str' a pure guess but it worked.

You may also be interested in the repr() function.  I'm afraid 
neither will give you

   123 --> "1 2 3"

but will give you "123" instead.

-tkc







More information about the Python-list mailing list