`<<` 是否等同于 python 3 中的 `pow(2,n)`?

Is `<<` equivalent to `pow(2,n)` in python 3?

在 python 文档中 python 3.5 https://docs.python.org/3/library/stdtypes.html

据说左移 int << n 相当于 int * pow(2,n) 但没有溢出检查。

但是由于 python 自动将整数提升为任意精度的长整数,这是否意味着实际上没有区别(因为不会溢出)?

您不必担心 Python 中的溢出,除非您使用的操作涉及可能溢出的数据类型。这不包括 Python 的内置数字类型(intfloatlongcomplex)。

对于 n 的正值,文档成立。他们指定进行溢出检查的原因是因为外部库,尤其是那些用 C 实现的库,如果不进行此类检查,就会发生溢出。

pow 的文档中所述,这也等同于 int * (2**n)