Glossary · Phase 7 · Software engineering
Special method
A method with double underscores, like __len__ or __add__, that Python calls for built-in syntax such as len(x) or a + b.
Try it now
sum() starts with 0, so the first step calls __radd__; after that, __add__ joins the amounts. print() finally calls __repr__ (there's no __str__).
Learn it properly
Make your classes feel built in · Special methods for printing, equality, ordering, arithmetic and containers. About 40 minutes.
Never trained an AI?
Teach a small one to write, right in your browser. It takes about 20 seconds and needs no account.