Skip to content

Commit 425d615

Browse files
author
Özgür Vatansever
committed
note added on string concatenation
1 parent 7b180cc commit 425d615

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

docs/writing/structure.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,22 @@ should be your preferred method.
463463
foo += 'ooo' # This is bad, instead you should do:
464464
foo = ''.join([foo, 'ooo'])
465465
466+
.. note::
467+
You can also use the **%** formatting operator to concatenate the
468+
pre-determined number of strings besides **join()** and **+**. However,
469+
according to `PEP 3101 <http://www.python.org/dev/peps/pep-3101/>`_,
470+
**%** operator became deprecated in Python 3.1 and will be replaced by the
471+
**format()** method in the later versions.
472+
473+
.. code-block:: python
474+
foo = 'foo'
475+
bar = 'bar'
476+
477+
foobar = '%s%s' % (foo, bar) # It is OK
478+
foobar = '{0}{1}'.format(foo, bar) # It is better
479+
foobar = '{foo}{bar}'.format(foo=foo, bar=bar) # It is best
480+
481+
466482
Vendorizing Dependencies
467483
------------------------
468484

0 commit comments

Comments
 (0)