mirror of
https://github.com/satwikkansal/wtfpython
synced 2024-11-25 12:34:23 +01:00
Add figure related to string intern
This commit is contained in:
parent
9ac6470efc
commit
674fc891b4
1
README.md
vendored
1
README.md
vendored
@ -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 `!`.
|
||||
<img src="/images/string-intern/string_intern.png" alt="">
|
||||
+ 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.
|
||||
|
||||
---
|
||||
|
Loading…
Reference in New Issue
Block a user