Newbie Question

Tom Culliton culliton at clark.net
Wed Sep 22 10:04:20 EDT 1999


In article <002f01bf04e6$7d6a4950$f29b12c2 at secret.pythonware.com>,
Fredrik Lundh <fredrik at pythonware.com> wrote:
>Chris... <sca at isogmbh.de> wrote:
>> I've never heard of an 'atoi' function, but there exists 'int()' that
>> converts its argument (string or number) to a plain integer.
>
>atoi is in the string module, together with atof and atol:
>
>http://www.python.org/doc/current/lib/module-string.html
>
>(they're similar to their builtin counterparts, but atoi
>and atol can also be used with non-decimal numbers)
>
></F>

string.atoi(), string.atof(), ... are also substantially faster (about
twice as fast by my tests) than int(), float() and the like.  This is
presumably because they don't need to waste time figuring out the type
of the input argument.  Generally I would recommednd using int() when
you need to coerce a "number" of arbitrary type to an integer (like
you would a C/C++ cast), and using string.atoi() to interpret strings
as integers.




More information about the Python-list mailing list