Macaulay2 » Documentation
Packages » Python » PythonObject » PythonObject - PythonObject » PythonObject -= Thing
next | previous | forward | backward | up | index | toc

PythonObject -= Thing -- augmented subtraction of Python objects

Description

Subtract two Python objects and assign the result to the first argument.

i1 : x = toPython 5

o1 = 5

o1 : PythonObject of class int
i2 : x -= toPython 3

o2 = 2

o2 : PythonObject of class int
i3 : x

o3 = 2

o3 : PythonObject of class int

If the right-hand side is a Macaulay2 object, then it is first converted to a Python object before subtracting.

i4 : x = toPython 9

o4 = 9

o4 : PythonObject of class int
i5 : x -= 5

o5 = 4

o5 : PythonObject of class int
i6 : x

o6 = 4

o6 : PythonObject of class int

If the Python class of x defines an __isub__ method for in-place subtraction, then it will be called. Otherwise, x and y will be subtracted in the usual way, creating a new Python object that is assigned back to x.

For example, Python sets support in-place subtraction. In the example below, x is modified directly, and no new object is created.

i7 : x = toPython set {1, 2, 3}

o7 = {1, 2, 3}

o7 : PythonObject of class set
i8 : x -= set {3}

o8 = {1, 2}

o8 : PythonObject of class set
i9 : x

o9 = {1, 2}

o9 : PythonObject of class set

See also

Ways to use this method:


The source of this document is in Python/doc/arithmetic.m2:162:0.