Python札記1:字符串駐留(String Interning)

在Python中操作字符串時,有時可能會遇到一些奇怪的現象,例如下面這個例子: >>> a = "hello" >>> b = "hello" >>> a is b True >>> a = "hello world" >>> b = "hello world" >>> a is b False 你可能會問:爲什麼會這樣呢?答案是Python中有一種稱爲「字符串駐留(String Internni
相關文章
相關標籤/搜索