What does str(...) do?

Evan Simpson evan at 4-am.com
Fri Feb 11 10:25:00 EST 2000


Peter Bittner <bittneph at aston.ac.uk> wrote in message
news:38A41077.9BDAE248 at aston.ac.uk...
> I've seen
>
>     print '....' + str(text) + '...'
>
> in some code (in a function definition).
> What does this 'str(...)' really do? - Is it absolutely necessary??

It's probably there because the author wasn't sure they could count on
'text' being a string, despite its name, so they force it to be one.
Whether that's a valid way to deal with the situation is entirely
context-dependent.

Cheers,

Evan @ 4-am





More information about the Python-list mailing list