Style question - defining immutable class data members
M R A Barnett
pcw at mrabarnett.plus.com
Sun Mar 15 13:27:43 EDT 2009
Aaron Brady wrote:
[snip]
> However, in my (opined) interpretation, 'list.append(...) is an in-
> place operation' is a factual error. In-place operations -also-
> rebind their 'argument' (FLOBW for lack of better words). 'append' is
> a by-side-effect operation. However colloquially it's mostly
> accurate.
>
[snip]
All the augmented assignments rebind, even for objects which support
in-place operations. For example:
my_list = []
my_list += [0]
rebinds, but the equivalent:
my_list = []
my_list.extend([0])
doesn't.
Augmented assignments which don't support in-place operations behave
like normal assignments (binding). For example:
my_int = 0
my_int += 1
behaves like:
my_int = 0
my_int = my_int + 1
More information about the Python-list
mailing list