Do I need to convert string to integer in python?
Steven D'Aprano
steve at REMOVETHIScyber.com.au
Sun Feb 26 16:41:41 EST 2006
On Sun, 26 Feb 2006 11:55:54 -0800, Allerdyce.John wrote:
> Do I need to convert string to integer in python? or it will do it for
> me (since dynamic type)?
>
> In my python script, I have this line:
> x /= 10;
>
> when i run it, I get this error:
> TypeError: unsupported operand type(s) for /=: 'unicode' and 'int'
No, the Python interpreter is playing a practical joke on you when it
raises that exception. Just persevere with the x /= 10 line, and
eventually the interpreter will give in and give you the result you need.
But be warned, if it is in a particularly playful mood, you may need to
try hundreds of times before it will stop messing about and get back to
work.
By the way, semi-colons are not required at the end of lines in Python.
--
Steven.
More information about the Python-list
mailing list