Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Object-Oriented Python Advanced Objects Subclassing Built-ins

Suraj Shah
Suraj Shah
1,055 Points

copy.copy(value)

Please could you explain why Kenneth uses copy.copy(value).

1) why can we not use copy(value)?

2) why copy.copy?

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

A good question! It does seem silly but there is a reason for this. As mentioned in the docs,

Assignment statements in Python do not copy objects, they create bindings between a target and an object.

Lists and strings (a special list, actually) have the slice notation, but other objects may or may not have a copying function build in. That's is where copy is useful.

The first copy is the library module copy, the second copy is the function that performs the actual copying.

Had Kenneth using the import statement from copy import copy then you could use copy(object) directly. However, by using import copy you get the module and to reference the function you need to use the form module.function.

Post back if you need anymore help!