Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #173 from kylerob/concat-example

Add code example to demonstrate proper string concatenation.
  • Loading branch information...
commit 93498b972708af8e7d21b86db48b5d2bccf88b8b 2 parents 50e6613 + 62e59a5
@kennethreitz authored
Showing with 20 additions and 0 deletions.
  1. +20 −0 docs/writing/structure.rst
View
20 docs/writing/structure.rst
@@ -391,6 +391,26 @@ its parts, it is much more efficient to accumulate the parts in a list,
which is mutable, and then glue ('join') the parts together when the
full string is needed.
+**Bad**
+
+.. code-block:: python
+
+ # create a concatenated string from 0 to 19 (e.g. "012..1819")
+ nums = ""
+ for n in range(20):
+ nums += str(n) # slow and inefficient
+ print nums
+
+**Good**
+
+.. code-block:: python
+
+ # create a concatenated string from 0 to 19 (e.g. "012..1819")
+ nums = []
+ for n in range(20):
+ nums.append(str(n))
+ print "".join(nums) # much more efficient
+
Vendorizing Dependencies
------------------------
Please sign in to comment.
Something went wrong with that request. Please try again.