From 674fc891b47969cb308adf14af82a711eeec8cd7 Mon Sep 17 00:00:00 2001 From: Satwik Kansal Date: Tue, 23 Jan 2018 14:37:22 +0530 Subject: [PATCH] Add figure related to string intern --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d04e078..a33db80 100644 --- a/README.md +++ b/README.md @@ -561,6 +561,7 @@ Makes sense, right? * All length 0 and length 1 strings are interned. * Strings are interned at compile time (`'wtf'` will be interned but `''.join(['w', 't', 'f']` will not be interned) * Strings that are not composed of ASCII letters, digits or underscores, are not interned. This explains why `'wtf!'` was not interned due to `!`. + + When `a` and `b` are set to `"wtf!"` in the same line, the Python interpreter creates a new object, then references the second variable at the same time. If you do it on separate lines, it doesn't "know" that there's already `wtf!` as an object (because `"wtf!"` is not implicitly interned as per the facts mentioned above). It's a compiler optimization and specifically applies to the interactive environment. ---