概述
我们知道**代表次方。
如下
>>>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')
最后
以上就是直率铃铛为你收集整理的Python3中运算符 **和*的区别的全部内容,希望文章能够帮你解决Python3中运算符 **和*的区别所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复