Do I need to convert string to integer in python?
Michael Amrhein
michael at adrhinum.de
Sun Feb 26 15:11:56 EST 2006
Allerdyce.John at gmail.com schrieb:
> 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'
>
> I want to divide x by 10 and assign that value back to x.
>
> Thank you.
>
>>> x=100
>>> x/=10
>>> x
10
>>> x='100'
>>> x/=10
Traceback (most recent call last):
File "<pyshell#4>", line 1, in -toplevel-
x/=10
TypeError: unsupported operand type(s) for /=: 'str' and 'int'
>>> x=int(x)/10
>>> x
10
Michael
More information about the Python-list
mailing list