When I read "Learning Python", I'm confused about using the is
operator.
The book tries to explain it as a test for the same memory address (A is B
, if True
, means A and B are in the same memory address) but in the following case, this explanation seems to not hold. Who can help me understand this function?
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: what kind of format do strings exist in memory?