当我阅读“Learning Python”时,我对使用is
运算符感到困惑。
本书试图将其解释为对相同内存地址的测试(A is B
, if True
,表示 A 和 B 位于同一内存地址中),但在以下情况下,这种解释似乎不成立。谁能帮我理解这个功能?
s2='ufysdjkhflakjhsdjkfhasdhfoqwhefuhalskdjfhwuioehfjkasdhfljahsdjwade'
s1='ufysdjkhflakjhsdjkfhasdhfoqwhefuhalskdjfhwuioehfjkasdhfljahsdjwade'
s1==s2,s1 is s2
(True, True)
s1='flashmanfdsafsdfasdfsdffgj;djg;alkjdfgl;kajdfl;gjkla;dfjg;lakdfj;'
s2='flashmanfdsafsdfasdfsdffgj;djg;alkjdfgl;kajdfl;gjkla;dfjg;lakdfj;'
s1==s2,s1 is s2
(True, False)
s2='ufysdjkhflakjhsdjkfhasdhfoqwhefuhalskdjfhwuioehfjkasdhfljahsdjwade'
s1='ufysdjkhflakjhsdjkfhasdhfoqwhefuhalskdjfhwuioehfjkasdhfljahsdjwade'
s1==s2,s1 is s2
(True, True)
s1=';;'
s2=';;'
s1==s2,s1 is s2
(True, False)
PS:字符串在内存中存在什么样的格式?