__pos__

Dunder MethodPython 2.0+Advanced

Defines behavior for the unary + positive operator

Quick Info

Documentation
Official Docs
Python Version
2.0+

Learn by Difficulty

Quick Example

python
class Example:
    def __pos__(self):
        return "Example __pos__"

obj = Example()
print(obj)

__pos__ defines behavior for the unary + positive operator. Implementing it lets you customize how Python interacts with your objects.

Try in Playground

Tags

oopmagic-methodprotocolcore