building strings from variables

wesley chun wescpy at gmail.com
Thu Oct 5 19:21:28 EDT 2006


> Following a discussion with an associate at work about various ways to
build strings from variables in python, I'd like to hear your opinions
and preferred methods.


from the performance standpoint, i believe that #4 (list join) from
scott is the fastest. #1 (string formatting) is next preferred only
because #3 (string concat) is the worst [think "realloc()"].  #2 is
useful for when you have users who aren't as comfortable with #1.

however, #3 is good for real newbies or those coming from other
languages since conceptually, it's the easiest to comprehend. bottom
line is that it depends on your requirements.

i'm constantly thinking performance, so that's why i answered in the
manner above.

hope this helps!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
    http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com



More information about the Python-list mailing list