471,355 Members | 2,037 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,355 software developers and data experts.

Deferred text formatting

bartonc
6,596 Expert 4TB
Did you know that it's perfectly legal to defer text formatting until you have the value(s) available? Watch this:
Expand|Select|Wrap|Line Numbers
  1. s = "%d apples plus %d apples equals %d apples."
  2.  
  3. yours = 3
  4. mine = 4
  5.  
  6. print s %(yours, mine, (yours + mine))
I had labored under the assumption that the format character required something to fill it at the time of assignment.
Oct 22 '07 #1
1 1173
bartonc
6,596 Expert 4TB
Expand|Select|Wrap|Line Numbers
  1. s = "%d apples plus %d apples equals %d apples."
  2.  
  3. yours = 3
  4. mine = 4
  5.  
  6. print s %(yours, mine, (yours + mine))
Of course, if this is done to far away (in lines of code) from the assignment, it's a bit tricky distinguishing this from a modulo (%) operation.
Oct 22 '07 #2

Post your reply

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

Similar topics

2 posts views Thread by SK | last post: by
1 post views Thread by Anthony Martin | last post: by
3 posts views Thread by Bryan | last post: by
7 posts views Thread by news | last post: by
3 posts views Thread by michael sorens | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.