问题描述
我的问题是打印语句中的 .
和 :
是什么?例如:
print(f'The estimated revenue for a $350 film is around ${revenue_estimate:.10}.')
返回:
The estimated revenue for a $350 film is around $600000000.0.
但是如果没有 :
和 .
,结果是完全一样的!
我搜索了一下,一无所获...
解决方法
我相信这个符号指定了输入的类型。在这种情况下,它是一个 float
削减到 10 个小数位,所以写
revenue_estimate = 4
print(f'The estimated revenue for a $350 film is around ${revenue_estimate:.10}.')
将产生以下结果:
ValueError Traceback (most recent call last)
<ipython-input-61-865ae2076242> in <module>()
1 revenue_estimate = 4
----> 2 print(f'The estimated revenue for a $350 film is around ${revenue_estimate:.10}.')
ValueError: Precision not allowed in integer format specifier
和 4.01234567894 将被削减到 4.0123456789