Newbie question: Returning mutable vs. immutable
Roy Smith
roy at panix.com
Thu Apr 15 10:38:16 EDT 2004
In article <997a06e0.0404150627.5fb95d9b at posting.google.com>,
pugnatio2 at yahoo.com wrote:
> Hi, Does anyone have an opinion as to whether functions/methods should
> return mutable or immutable objects? In some circumstances, I could
> see that mutable objects might be more convenient, but if the function
> is to be reused, it might be a good idea to return only immutables.
>
> Or is this question moot, since the function returns control to the
> caller and is out of the picture at that point?
>
> Thanks,
>
> --p
I don't think there's any general rule for this. Return what makes
sense to return and don't worry about the mutability unless there's some
specific reason it needs to be mutable (i.e. you're going to change it)
or immutable (i.e. you're going to use it as a dictionary key).
More information about the Python-list
mailing list