From f98bd4363ff18e07347350061f7d68102c41cbc8 Mon Sep 17 00:00:00 2001 From: Satwik Kansal Date: Mon, 30 Dec 2019 13:05:38 +0530 Subject: [PATCH] Fix typo Closes https://github.com/satwikkansal/wtfpython/issues/164 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8ef9d5d..5afc1f1 100644 --- a/README.md +++ b/README.md @@ -343,7 +343,7 @@ Makes sense, right? + After being "interned," many variables may reference the same string object in memory (saving memory thereby). + In the snippets above, strings are implicitly interned. The decision of when to implicitly intern a string is implementation-dependent. There are some rules that can be used to guess if a string will be interned or not: * 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 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 `!`. CPython implementation of this rule can be found [here](https://github.com/python/cpython/blob/3.6/Objects/codeobject.c#L19) ![image](/images/string-intern/string_intern.png) + 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 compile-time optimization. This optimization doesn't apply to 3.7.x versions of CPython (check this [issue](https://github.com/satwikkansal/wtfpython/issues/100) for more discussion).