[Tutor] Re: 'number' strings error

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Fri, 2 Mar 2001 19:02:00 -0800 (PST)


On Fri, 2 Mar 2001, Christopher Peet wrote:

> Sorry the waste bandwidth..... I just figured out I needed the string
> module and string.atoi.  I got it sorted now.

No problem, don't worry about it.


By the way, instead of using string.atoi(), you can use the int()
function, which will convert anything to an integer.  For example:

###
>>> age = int('42')
>>> print type(age)
<type 'int'>
###

It's easier to type than string.atoi('42'), and more versatile.  It can
work with floating point numbers too:

###
>>> average_children = int(3.5)
>>> average_children
3
###

Hope this helps!