How does python determine whether a string is hosted or not
This article mainly explains "python how to judge whether the string is resident", the content of the explanation is simple and clear, easy to learn and understand, now please follow the editor's train of thought slowly in depth, together to study and learn "python how to determine whether the string is resident" bar!
1. The declaration is defined in unicodeobject.h.
2. To check whether the string stays or not, CPython implements the PyUnicode_CHECK_INTERNED macro, which is also defined as unicodeobject.h.
PyAPI_FUNC (void) PyUnicode_InternInPlace (PyObject *)
This macro indicates that Python maintains a member variable named interned in the PyASCIObject structure, whose value indicates whether the corresponding string is retained.
# define PyUnicode_CHECK_INTERNED (op)\ (PyASCIIObject *) (op))-> state.interned)
Development
If two string objects refer to the same memory object, the is operator will get True, otherwise it will be False.
> Here is, the editor will push for you more related knowledge points of the article, welcome to follow!