What happens behind the scenes when python adds small ints? [duplicate]
问题 This question already has answers here : “is” operator behaves unexpectedly with integers (11 answers) Closed 4 years ago . I was fiddling around with id recently and realized that (c?)Python does something quite sensible: it ensures that small ints always have the same id . >>> a, b, c, d, e = 1, 2, 3, 4, 5 >>> f, g, h, i, j = 1, 2, 3, 4, 5 >>> [id(x) == id(y) for x, y in zip([a, b, c, d, e], [f, g, h, i, j])] [True, True, True, True, True] But then it occurred to me to wonder whether the