By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,835 Members | 1,173 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,835 IT Pros & Developers. It's quick & easy.

formatted printing

P: 1
sir,
Expand|Select|Wrap|Line Numbers
  1. a=2.0/3
  2. print a
  3. print'a=%5.3f'%(a)
in the above python code what is the use of 5 in 5.3.i think 3 is the number of decimal places.but i cant understand what is this 5 represnts.please help me.
Mar 23 '12 #1
Share this Question
Share on Google+
1 Reply

bvdet
Expert Mod 2.5K+
P: 2,851
The 5 in the 5.3 is the minimum field width. If a negative number, the padding occurs on the right.
Expand|Select|Wrap|Line Numbers
  1. >>> n = 20000000.123456789
  2. >>> print "n = %5.3f" % (n)
  3. n = 20000000.123
  4. >>> n = 0.123456789
  5. >>> print "n = %5.3f" % (n)
  6. n = 0.123
  7. >>> print "n = %50.3f" % (n)
  8. n =                                              0.123
  9. >>> 
Mar 23 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.