搜尋此網誌

2023年10月8日星期日

Python Calculation

 

Formatted string literals (f-strings) let you include the value of Python expressions inside a string by prefixing the string with f or F and writing expressions as {expression}.

An optional format specifier can follow the expression. This allows greater control over how the value is formatted. The following example rounds pi to three places after the decimal:

>>> import math

>>> print(f'The value of pi is approximately {math.pi:.3f}.')

The value of pi is approximately 3.142.

沒有留言:

發佈留言