integer copy

ast nomail at com.invalid
Fri Oct 20 04:30:05 EDT 2017


Hello, I tried the following:

import copy

a = 5
b = copy.copy(a)

a is b
True

I was expecting False

I am aware that it is useless to copy an integer
(or any immutable type). 

I know that for small integers, there is always a
single integer object in memory, and that for larger
one's there may have many.

a = 7
b = 7
a is b
True

a = 56543
b = 56543
a is b
False

But it seems that Python forbids to have two different
small integer objects with same value even if you
request it with:

a = 5
b = copy.copy(a)

any comments ?





More information about the Python-list mailing list