.
和:
在print语句中做什么?
例如:
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.
但是如果没有:
和.
,结果是完全一样的!
我找遍了什么也没找到...
.
和:
在print语句中做什么?
例如:
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.
但是如果没有:
和.
,结果是完全一样的!
我找遍了什么也没找到...
2条答案
按热度按时间krugob8w1#
以下是您的答案:
https://blog.teclado.com/python-formatting-numbers-for-printing/
我也在研究同样的问题,也把我弄糊涂了。
在冒号后面,指定要打印的有效数字位数。由于您的答案60000000.0正好有10个有效数字,因此将打印整个结果。如果您将代码更改为:
print(f'The estimated revenue for a $350 film is around ${revenue_estimate:.9}.')
,您将看到以指数表示法表示的输出6e+08cbjzeqam2#
我相信这种表示法指定了输入的类型,在本例中,它是一个
float
,它被削减到10个小数位,因此将产生以下结果:
和4.01234567894将被切割为4.0123456789