all Python 3operatorfunction
operator.isub
in-place
In-place subtraction: a -= b; for sets, an in-place difference.
Syntax
operator.isub(a, b)
For numbers nothing changes in place — assign the result: x = isub(x, 1). For a set it mutates in place, removing the second argument's items: after isub(s, {1}) the 1 is gone from s, and every reference to that object sees it. Lists have no -= at all: isub([1, 2], [1]) raises TypeError.
Examples
import operator
print(operator.isub(5, 2)) # → 3
print(operator.isub(0.3, 0.1)) # → 0.19999999999999998
tags = {'a', 'b', 'c'}
print(operator.isub(tags, {'b'}) is tags) # → True
print(sorted(tags)) # → ['a', 'c']
print(operator.isub([1, 2, 3], [2])) # → TypeError
See also
Open in the full glossarydocs.python.orgReport an inaccuracy