mirror of
https://github.com/kennethreitz/python-guide.git
synced 2026-06-05 14:50:19 +00:00
Separate join and list comprehension
This commit is contained in:
@@ -445,7 +445,8 @@ with calls to append().
|
|||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
# create a concatenated string from 0 to 19 (e.g. "012..1819")
|
# create a concatenated string from 0 to 19 (e.g. "012..1819")
|
||||||
print "".join([str(n) for n in range(20)])
|
nums = [str(n) for n in range(20)]
|
||||||
|
print "".join(nums)
|
||||||
|
|
||||||
One final thing to mention about strings is that using join() is not always
|
One final thing to mention about strings is that using join() is not always
|
||||||
best. In the instances where you are creating a new string from a pre-determined
|
best. In the instances where you are creating a new string from a pre-determined
|
||||||
|
|||||||
Reference in New Issue
Block a user