⚡String interning in Python
The first one is folded at compile time into the same interned constant.
The second is built at runtime, so it's a new object.
sys.intern puts it into the shared table, where dict lookups can match keys by pointer before comparing characters.
python
a = "hel" print("hel" + "lo" is "hello") # True print(a + "lo" is "hello") # False print(sys.intern(a + "lo") is "hello") # True
commit c5045f0