Added comment about joining strings

This commit is contained in:
Jeremy Fincher 2003-03-25 08:20:41 +00:00
parent 2b7e8c7a2f
commit 5af91f0677
1 changed files with 7 additions and 0 deletions

View File

@ -53,3 +53,10 @@ argument list as their first line, and (if necessary) a blank line followed by
a longer description of what the command does. The argument list is used by
the 'help' command, and the longer description is used by the 'morehelp'
command.
Whenever joining more than two strings, use string interpolation, not addition:
s = x + y + z # Bad.
s = '%s%s%s' % (x, y, z) # Good.
s = ''.join(x, y, z) # Best, but not as general.
This has to do with efficiency; the intermediate string x+y is made (and thus
copied) before x+y+z is made, so it's less efficient.