Get the App
SLTechnology News&Howtos  ›  Development  › 

How does python determine whether a string is hosted or not

Shulou Source: shulou.com Published: 2022-06-03 17:30:55 11月13日 Update

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!

Tags: Characters strings learning content objects same two memory variables that is ideas situations members articles more knowledge knowledge points articles structures follow Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Microsoft vpn Shulou Tech Info Xiaomi