memory location in unicode strings

前端 未结 2 1295
暗喜
暗喜 2021-01-19 01:11

I know someone explain why when I create equal unicode strings in Python 2.7 they do not point to the same location in memory As in \"normal\" strings

>&g         


        
2条回答
  •  死守一世寂寞
    2021-01-19 01:26

    I think regular strings are interned but unicode strings are not. This simple test seems to support my theory (Python 2.6.6):

    >>> intern("string")
    'string'
    >>> intern(u"unicode string")
    
    Traceback (most recent call last):
      File "", line 1, in 
        intern(u"unicode string")
    TypeError: intern() argument 1 must be string, not unicode
    

提交回复
热议问题