Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

1. operators use special lookup for dunder methods--on class, not on instance:

    >>> a+1 # lookup on class 
    1+1
    2 
    >>> a.__add__(1) # instance method 
    0
2. There is __radd__ that is called if __add__ doesn't support given types (for different types).


Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: