Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding the print format %.3 in python

Tags:

python

Can someone help me with the explanation of what the "'f %" meaning in the following code?

print('Slope: %.3f' % lr.w_[1])
like image 721
Ze4 Avatar asked Dec 10 '22 06:12

Ze4


1 Answers

Here is a list of string formatting options in Python. You use a % as a placeholder, which is replaced by lr.w_[1] in this case. The f then refers to "Floating point decimal format". The .3 indicates to round to 3 places after the decimal point.

like image 98
R Balasubramanian Avatar answered Jan 01 '23 18:01

R Balasubramanian