我们知道**代表次方。
如下
>>>12 * 12
144
>>>12 ** 2
144
>>>a=1e200
>>> a
1e+200
>>>a ** 2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: (34, 'Result too large')
>>>a * a
inf
>>>a = 100 ** 100 # python3中int整型一般不会溢出,取决于内存
100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
>>>a * a,a ** 2 # 两种方式都没问题,int很大,不会溢出,取决于内存
(10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)
>>>float(a) * float(a) #float用这种方法,也不会溢出
inf
>>>float(a) ** 2 #float用这种方式有可能溢出,注意!!!
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: (34, 'Result too large')