シフト演算

A right shift by n bits is defined as division by pow(2,n). A left shift by n bits is defined as multiplication with pow(2,n); for plain integers there is no overflow check so in that case the operation drops bits and flips the sign if the result is not less than pow(2,31) in absolute value. Negative shift counts raise a ValueError exception.

ふむふむ。

% python2.5
Python 2.5.1 (r251:54863, Apr 25 2007, 22:53:30)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 1 << 31
2147483648L
>>>

あれ?

% python2.3
Python 2.3.6 (#2, Jul  3 2007, 05:33:34)
[GCC 4.1.3 20070601 (prerelease) (Debian 4.1.2-12)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 1 << 32
__main__:1: FutureWarning: x<<y losing bits or changing sign will return a long in Python 2.4 and up
0
>>> 1 << 31
-2147483648
>>>

むぅ。わざわざ Python 2.3 で警告メッセージが出るようになっているのにドキュメントが更新されていないよ!