From 425d6155e0fa04e6c73d8fa939240f843a0b01d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=CC=88zgu=CC=88r=20Vatansever?= Date: Sun, 31 Mar 2013 18:23:42 +0300 Subject: [PATCH 1/2] note added on string concatenation --- docs/writing/structure.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/writing/structure.rst b/docs/writing/structure.rst index 9f5a1a270..8291cb6fc 100644 --- a/docs/writing/structure.rst +++ b/docs/writing/structure.rst @@ -463,6 +463,22 @@ should be your preferred method. foo += 'ooo' # This is bad, instead you should do: foo = ''.join([foo, 'ooo']) +.. note:: + You can also use the **%** formatting operator to concatenate the + pre-determined number of strings besides **join()** and **+**. However, + according to `PEP 3101 `_, + **%** operator became deprecated in Python 3.1 and will be replaced by the + **format()** method in the later versions. + +.. code-block:: python + foo = 'foo' + bar = 'bar' + + foobar = '%s%s' % (foo, bar) # It is OK + foobar = '{0}{1}'.format(foo, bar) # It is better + foobar = '{foo}{bar}'.format(foo=foo, bar=bar) # It is best + + Vendorizing Dependencies ------------------------ From 328df72c4f798e56879fb42fd2946c2bf1dd5fc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=CC=88zgu=CC=88r=20Vatansever?= Date: Sun, 31 Mar 2013 22:19:16 +0300 Subject: [PATCH 2/2] code block newline added --- docs/writing/structure.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/writing/structure.rst b/docs/writing/structure.rst index 8291cb6fc..1280c1fd0 100644 --- a/docs/writing/structure.rst +++ b/docs/writing/structure.rst @@ -471,6 +471,7 @@ should be your preferred method. **format()** method in the later versions. .. code-block:: python + foo = 'foo' bar = 'bar'