semantics of the |= operator

akva kiruta at gmail.com
Fri Aug 22 03:35:31 EDT 2008


thanks all,

>Yes. That's the exact purpose of the in-place operators when they deal with
>mutable objects. What else did you expect?

well, frankly I expected a |= b to mean exactly the same as a = a | b
regardless of the object type.

> The manual explicitly specifies that mutable objects may implement the
> operation part of operation-assignments by updating in place  -- so that
> the object assigned is a mutated version of the original rather than a
> new object.

could you please refer me a link where this is specified? I couldn't
find it
in python documentation

> This has nothing to do with being inside a function.

yes, I know. maybe my example is a bit too verbose. could avoid using
functions.
But you got my main point. I found it somewhat counter-intuitive that
operation-assignments
can modify value in place.

Regards,
Vitali



More information about the Python-list mailing list