Python (like Java, C, C++, .NET) uses string pooling / interning. The interpreter realises that “hello” is the same as “hello”, so it optimizes and uses the same location in memory.
Another goodie: "hell" + "o" is "hello"
==> True
More Related Contents:
- “is” operator behaves unexpectedly with integers
- Why does comparing strings using either ‘==’ or ‘is’ sometimes produce a different result?
- Comparing a string to multiple items in Python
- Why does id({}) == id({}) and id([]) == id([]) in CPython?
- How do I compare version numbers in Python?
- Good Python modules for fuzzy string comparison? [closed]
- The `is` operator behaves unexpectedly with non-cached integers
- Checking whether a string starts with XXXX
- Two variables in Python have same id, but not lists or tuples
- Why don’t methods have reference equality?
- When to use which fuzz function to compare 2 strings
- Version number comparison in Python
- python is operator behaviour with string [duplicate]
- String similarity with Python + Sqlite (Levenshtein distance / edit distance)
- Confused about Python’s id() [duplicate]
- Why does the “is” keyword have a different behavior when there is a dot in the string?
- Why is a method not identical to itself?
- Take first some character of string but if particular character will come consider that character also
- Sharing a result queue among several processes
- “ImportError: No module named site” on Windows
- How to compare two JSON objects with the same elements in a different order equal?
- How do I use np.newaxis?
- How would I build python myself from source code on Ubuntu?
- gcc-4.2 failed with exit status 1
- Configure Django and Google Cloud Storage?
- Selenium “Unable to find a matching set of capabilities” despite driver being in /usr/local/bin
- How to create a dictionary of two pandas DataFrame columns
- A way to subclass NamedTuple for purposes of typechecking
- Uninstall python built from source?
- Should I use instance or class attributes if there will only be one instance? [closed]