From the docs:
Many operations have an “in-place” version. The following functions provide a more primitive access to in-place operators than the usual syntax does; for example, the statement x += y is equivalent to x = operator.iadd(x, y). Another way to put it is to say that z = operator.iadd(x, y) is equivalent to the compound statement z = x; z += y.
Questions:
Why isn't
operator.iadd(x, y)
equivalent toz = x; z += y
?How does
operator.iadd(x, y)
differ fromoperator.add(x, y)
?
Related question, but I'm not interested in Python class methods; just regular operators on built-in Python types.