Python 3.12+sysfunction
sys.getunicodeinternedsize()
strings
Returns how many strings are currently interned — kept as single copies in the interpreter's shared table.
Syntax
sys.getunicodeinternedsize()
Thousands of strings are interned at startup: Python interns attribute and function names and identifier-like literals on its own. sys.intern() adds a new string, while calling it again with the same string adds nothing. It is a utility for exploring memory and the interpreter itself, almost never for application code.
Examples
import sys
print(sys.getunicodeinternedsize() > 1000) # → True
word = ''.join(['uniq', 'ue', '_word_42'])
before = sys.getunicodeinternedsize()
sys.intern(word)
print(sys.getunicodeinternedsize() - before) # → 1
sys.intern(word)
print(sys.getunicodeinternedsize() - before) # → 1
See also
Open in the full glossarydocs.python.orgReport an inaccuracy