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

Jan Durcak
Jan Durcak
12,662 Points

why is it working without copy.copy?

for _ in range(count): self.append(value)

1 Answer

Steven Parker
Steven Parker
229,921 Points

It's probably working because you're testing it with an immutable value.   Or it might just look like it's working because of how you use the created instance, particularly if you never change anything in it.

Ken explains this about 6 minutes into the video, when he says:

Now why am I using copy.copy?   Well, if they send in something mutable, like say, another list, each member in that filled list or each member in our filled list that was a copy of that list would be the same member if we weren't using copy.copy.   If you changed one of them it would change all of the others too, because we're just putting in references to that list.