From e836b22a36e7084019fb249dd6034c353cdeca5e Mon Sep 17 00:00:00 2001 From: Satwik Kansal Date: Mon, 11 Sep 2017 22:09:58 +0530 Subject: [PATCH] String concatenation optimizations: Update title * Modifies the previously misleading title to be more precise. Related to https://github.com/satwikkansal/wtfpython/issues/38 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5e854d5..4234652 100755 --- a/README.md +++ b/README.md @@ -455,7 +455,7 @@ def convert_list_to_string(l, iters): --- -### String concatenation interpreter optimizations. +### String interning ```py >>> a = "some_string" @@ -473,7 +473,7 @@ def convert_list_to_string(l, iters): #### 💡 Explanation: + `+=` is faster than `+` for concatenating more than two strings because the first string (example, `s1` for `s1 += s2 + s3`) is not destroyed while calculating the complete string. -+ Both the strings refer to the same object because of CPython optimization hat tries to use existing immutable objects in some cases (implementation specific) rather than creating a new object every time. You can read more about this [here](https://stackoverflow.com/questions/24245324/about-the-changing-id-of-an-immutable-string) ++ Both the strings refer to the same object because of CPython optimization that tries to use existing immutable objects in some cases (implementation specific) rather than creating a new object every time. You can read more about this [here](https://stackoverflow.com/questions/24245324/about-the-changing-id-of-an-immutable-string). ---