returning data in python
Question: I'm currently looking through the "Dive Into Python" to pick up the language
and I was a bit confused about chapter 5's example 5.10. UserDict Normal
Methods

Example 5.10. UserDict Normal Methods

    
    
    def copy(self):
        if self.__class__ is UserDict:
            return UserDict(self.data)
        import copy
        return copy.copy(self)
    

where `data` is a dictionary.

I notice that if the class is a UserDict type, then it returns
`UserDict(self.data)`. What I'm confused about is, why do you need to return
`UserDict(self.data)` instead of just returning `self.data`? Isn't self.data a
dictionary which you can return?

If someone can explain the difference between returning `UserDict(self.data)`
and `self.data`, I would appreciate it greatly.


Answer: It returns a new `UserDict` object because `.copy()` is expected to return an
object of the same type its copying.

