[Tutor] a question about maxint

Alan Gauld alan.gauld at btinternet.com
Wed Oct 3 20:53:57 CEST 2012


On 03/10/12 12:33, eryksun wrote:
> On Wed, Oct 3, 2012 at 1:28 AM, Katya Stolpovskaya

>> Thank you for you reply, but with "long" I got the same error:
>>
>>>>> from sys import *
>>>>> long
>>
>> Traceback (most recent call last):
>> File "<pyshell#5>", line 1, in <module>
>> long
>> NameError: name 'long' is not defined
>
> I assumed some familiarity with Python 2, which has two integer
> arithmetic types: int (fixed precision, using the platform's C long
> type) and long (arbitrary precision). The naming is a bit conflated in
> that a Python int uses a C long, which has nothing to do with a Python
> long.
>

In case Katya didn't follow the technical stuff the bottom line is that 
'long' is not a name in Python. You should check maxsize rather than 
maxint but in practice you probably don't need to, just treat Python 
integers as being of arbitrary length:


 >>> bigInt = 25**45
 >>> print bigInt
807793566946316088741610050849573099185363389551639556884765625
 >>>

The only times you really need to worry about maxsize is when 
interfacing to external non-python code.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list