F-string in Python ":.3f" [duplicate]

I'm reading this textbook called "Practical Statistics for Data Scientists" and this :.3f keeps getting used in almost every f-string. What does :.3f mean? My guess is it has something to do with floating point numbers.

Example:

 {house_lm_factor.intercept_:.3f} 
2

1 Answer

This is show you how many number are printing:

>>> import math >>> flt = math.pi >>> f'{flt:.3f}' '3.142' >>> f'{flt:.5f}' '3.14159' >>> f'{flt:.10f}' '3.1415926536' 

You Might Also Like