Skip to content

Commit 674fc89

Browse files
committed
Add figure related to string intern
1 parent 9ac6470 commit 674fc89

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ Makes sense, right?
561561
* All length 0 and length 1 strings are interned.
562562
* Strings are interned at compile time (`'wtf'` will be interned but `''.join(['w', 't', 'f']` will not be interned)
563563
* Strings that are not composed of ASCII letters, digits or underscores, are not interned. This explains why `'wtf!'` was not interned due to `!`.
564+
<img src="/images/string-intern/string_intern.png" alt="">
564565
+ 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.
565566
566567
---

0 commit comments

Comments
 (0)