Returns the inverse val**-1 of the given value, if defined.

Used in the notebooks

Used in the tutorials

An object can define an inverse by defining a pow(self, exponent) method that returns something besides NotImplemented when given the exponent -1. The inverse of iterables is by default defined to be the iterable's items, each inverted, in reverse order.

val The value (or iterable of invertible values) to invert.
default Determines the fallback behavior when val doesn't have an inverse defined. If default is not set, a TypeError is raised. If default is set to a value, that value is returned.

If val has a pow method that returns something besides NotImplemented when given an exponent of -1, that result is returned. Otherwise, if val is iterable, the result is a tuple with the same items as val but in reverse order and with each item inverted. Otherwise, if a default argument was specified, it is returned.

TypeError val doesn't have a pow method, or that method returned NotImplemented when given -1. Furthermore val isn't an iterable containing invertible items. Also, no default argument was specified.