Comments (4)
By "they should be same" do you mean W's should be same in rect3
and rect4
output? If you are confused as such, it is just that update statements are different in code:
rect3.border_width = 9 # W:9
rect4.border_width = 11 # W:11
If you mean you were expecting rect1
and rect4
output to be same in terms of W at the deep copy part then it means you didn't understand what deep copy is doing. Please clarify, if your confusion was smt else.
from ceng2002.
At the last block, if "rect4 = deepcopy(rect1)" is deepcopy it has to do same work with "rect2 = rect1".
Output of rect2 = rect1 is:
rect1=A green with TP:(0,20,0) BR:(7,0,0) W:7)
rect2=A green with TP:(0,20,0) BR:(7,0,0) W:7)
Output of rect4 = deepcopy(rect1) is:
rect1=A green with TP:(0,40,0) BR:(7,0,0) W:7)
rect4=A pink with TP:(0,60,0) BR:(7,0,0) W:11)
If second one is a deepcopy why rect1 doesn't change when we modify rect4. We thought that there's a reference copy so that rect1 has to change with rect4.
from ceng2002.
As we understand we cannot deep copy objects in deepcopy method, just copy classes and modules.
from ceng2002.
rect4 = rect1
creates a reference (alias) to rect1
so updates to rect4
is actually updates to rect1
. If you don't want this behavior -i.e. want to change rect4
without changing rect1
- then you need to clone the object. That's what deepcopy
does in Python. So modifying rect4
doesn't modify rect1
even for references in rect1
like top_left_point
since that point is also cloned while creating rect4
.
from ceng2002.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ceng2002.