Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fee9fcd

Browse filesBrowse files
author
Kenneth Reitz
committed
Merge pull request realpython#261 from ozgur/string_concatenation_note
Note added on string concatenation
2 parents 08b8eec + 328df72 commit fee9fcd
Copy full SHA for fee9fcd

File tree

Expand file treeCollapse file tree

1 file changed

+17
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+17
-0
lines changed

‎docs/writing/structure.rst

Copy file name to clipboardExpand all lines: docs/writing/structure.rst
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,23 @@ 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+
475+
foo = 'foo'
476+
bar = 'bar'
477+
478+
foobar = '%s%s' % (foo, bar) # It is OK
479+
foobar = '{0}{1}'.format(foo, bar) # It is better
480+
foobar = '{foo}{bar}'.format(foo=foo, bar=bar) # It is best
481+
482+
466483
Vendorizing Dependencies
467484
------------------------
468485

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.