January 8th, 2005, 12:19 AM
String Formatting %
I am having probelms with string formatting. I have never used it before, but I see it in a lot of code examples. Can someone please help me understand what it does?
January 8th, 2005, 12:31 AM
One more thing :P
How do I add my avatar? I went to the edit avatar page but it has a little button that says I do not want to use an avatar. Even when I unclick it, it won't let me have one =(
January 8th, 2005, 02:24 PM
String formatting is basically a way of inserting values into a string at predefined points . So why use String Formatting over String Concatenation?
Mainly because it lends itself to smaller, cleaner looking code but it is also -- surposed to be -- more efficient than joining multiple strings using the + operator (especially inside loops!). Added to this, String formatting makes it surprisingly easy to do things like padding strings-and-numbers and representing floating point numbers to varying decimal places .
Anyway, there are a number of good texts out there on using String Formatting but here are a few of my favourites:
I would also suggest picking up a copy of O'Reillys "Learning Python", "Python in a Nutshell" or Mark Pilgrims "Dive Into Python" if you have a chance. All have good coverage on the subject and would be handy to have around anyway .
On to the avatar. As explained so elegantly by Edwin in the DevShed Lounge sticky (below) there are a few restrictions placed on new users, to prevent spamming and etc.
Hope this helps ,
January 8th, 2005, 06:46 PM
Thanks for the help. I don't plan to be a new user for long =) This is probably the best python forum I have found =)