PDA

View Full Version : Python: String to Int conversion?



Aran
05-05-2006, 09:55 PM
I've got a string from which i'm extracting a number. I can get the number out of the string as a string itself, but ican't get it to be an integer.

How do you do this in python? I don't see facilities for casting, nor do i see methods in the string class that would let me do this. There's no way that the language doesn't let you do this.

anonytmouse
05-05-2006, 10:06 PM
num = int(str);

This function can also take an optional radix. You can find the documentation at 2.1 Built-in Functions (http://docs.python.org/lib/built-in-funcs.html) (scroll down).