__complex__

Dunder MethodPython 2.0+Advanced

Called by complex(); returns a complex number representation

Quick Info

Documentation
Official Docs
Python Version
2.0+

Learn by Difficulty

Quick Example

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

obj = Example()
print(obj)

__complex__ called by complex(); returns a complex number representation. Implementing it lets you customize how Python interacts with your objects.

Try in Playground

Tags

oopmagic-methodprotocolcore