15.04.2013 Views

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Core</strong> Style: Use uppercase "L" with long integers<br />

Although <strong>Python</strong> supports a case-insensitive "L" to denote longs, we<br />

recommend that you use only the uppercase "L" to avoid confusion<br />

with the number one (1). <strong>Python</strong> will display only longs with a capital<br />

"L ." As integers and longs are slowly being unified, you will only see<br />

the "L" with evaluatable string representations (repr()) of longs.<br />

Printable string representations (str()) will not have the "L ."<br />

>>> aLong = 999999999l<br />

>>> aLong<br />

999999999L<br />

>>> print aLong<br />

999999999<br />

5.2.4. Unification of Integers and Long Integers<br />

Both integer types are in the process of being unified into a single integer type. Prior to <strong>Python</strong> 2.2,<br />

plain integer operations resulted in overflow (i.e., greater than the 232 range of numbers described<br />

above), but in 2.2 or after, there are no longer such errors.<br />

<strong>Python</strong> 2.1<br />

>>> 9999 ** 8<br />

Traceback (most recent call last):<br />

File "", line 1, in ?<br />

OverflowError: integer exponentiation<br />

<strong>Python</strong> 2.2<br />

>>> 9999 ** 8<br />

99920027994400699944002799920001L<br />

Removing the error was the first phase. The next step involved bit-shifting; it used to be possible to leftshift<br />

bits out of the picture (resulting in 0):<br />

>>> 2

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!