如何使用Python3的新特性:"f-string“来输出math.pi的前50位?
我们可以通过以下两种老方法来实现它:1字符串2,但是对于新特性“f- '{.50f}'.format(math.pi)”,我知道我们可以使用这样的格式:f“pi的值是{math.pi}",但是如何限制和过滤前50位?
In [2]: ("%.50f"%math.pi)
Out[2]: '3.14159265358979311599796346854418516159057617187500'发布于 2019-05-27 23:11:51
格式与str.format相同,但在:之前的第一个块中使用变量名
>>> import math
>>> f"{math.pi:.50f}"
'3.14159265358979311599796346854418516159057617187500'
>>> f"the value of pi is {math.pi:.50f}"
'the value of pi is 3.14159265358979311599796346854418516159057617187500'https://stackoverflow.com/questions/56328599
复制相似问题