Answer the question
In order to leave comments, you need to log in
Why is equality true?
Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> s = "test_string"
>>> id(s[1:5]) == id(s[2:6])
True
Answer the question
In order to leave comments, you need to log in
As stated in the official documentation for language version 2.7:
https://docs.python.org/2/library/functions.html?h...
[email protected]:~$ python
Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> s = 'test_string'
>>> id(s[1:5]) == id(s[2:6])
True
>>> id(s[1:5])
139620785926528
>>> id(s[2:6])
139620785926528
>>> print(id(s[1:5]))
139620785926384
>>> print(id(s[2:6]))
139620785926576
>>> print(id(s[1:5]), id(s[2:6]))
(139620785926528, 139620785926528)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question