#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    25
    Rep Power
    0

    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?
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    25
    Rep Power
    0
    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 =(
  4. #3
  5. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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:

    http://www.rexx.com/~dkuhlman/python_101/python_101.html
    http://diveintopython.org/native_data_types/formatting_strings.html
    http://www.python.org/doc/2.4/lib/typesseq-strings.html

    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.

    http://forums.devshed.com/t194545/s.html

    Hope this helps ,

    Mark.
    programming language development: www.netytan.com Hula

  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    25
    Rep Power
    0
    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 =)

IMN logo majestic logo threadwatch logo seochat tools logo