H
Harry George
Shah said:Hi Everybody,
Can you guide me to convert string into Int datatype?
(i.e. How can we convert string into int? like '555' into 555)
Thanks in advance.
~Rajesh
Others have answered with "int". You should also wrap that with an
exception handler, because your string might not actually be a number.
x=raw_input("Enter number") #actually got "one"
try:
y=int(x)
except ValueError:
print 'Use numeric numbers, e.g., "123", not "one two three"'
Also, "typecast" usually means "the same bits, but interpreted a
different way". E.g., reading an IEEE 32-bit float as an array of
bytes.
"Type coercion" means "convert the actual bits, so that the meaning is
similar but it is different in RAM". This is used for string<->int,
int<->float, etc.