Special Method Protocols

__pos__() — numeric protocol

Unary plus dispatches to this special method. Unary operations have no reflected fallback. The result is determined by the class; this example delegates to an integer.

Formal Syntax & Structure

python syntaxpython
def __pos__(self):

Return Value

object

Value produced by the hook.

Working Example

Example Snippetpython
class Number:    def __init__(self, value):        self.value = value    def __pos__(self):        return +self.valueprint(+Number(-7))
Python Reference