我刚试过
>>> 2.17 * 10**27
2.17e+27
>>> str(2.17 * 10**27)
'2.17e+27'
>>> "%i" % 2.17 * 10**27
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: cannot fit 'long' into an index-sized integer
>>> "%f" % 2.17 * 10**27
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: cannot fit 'long' into an index-sized integer
>>> "%l" % 2.17 * 10**27
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: incomplete format
现在我没主意了。我想得到
^{2}$我怎么能打印这么大的数字?(我不在乎是Python2.7+解决方案还是Python3.X解决方案)
你把你的操作员优先权弄错了。您正在格式化
2.17
,然后将其乘以一个长整数:在乘法的两边加上括号:
^{pr2}$这是为字符串格式重载module运算符的缺点之一;^{} method 使用的较新的Format String syntax和它使用的Format Specification Mini-Language巧妙地避开了这个问题。对于这个例子,我将使用
format()
:相关问题 更多 >
编程相关推荐