Copying

Copying an object is often an alternative to aliasing.The copy module contains a function called copy that can duplicate any object:

>>>p1=Point()
>>>p1.x=3.0
>>>p1.y=4.0
>>>import copy 
>>>p2=copy.copy(p1)
As p1 and p2 contain the same data,but they are not the same Point.
>>>print_point(p1)
(3.0,4.0)
>>>print_point(p2)
(3.0,4.0)
>>>p1 is p2
False
>>>p1==p2
False
Translate »