The built-in function abs() in Python calls the __abs__ dunder method on an object.
✅ Example:
🔍 What’s Happening:
When you write abs(temp), Python internally calls:
This allows you to define custom behavior for abs() on your own classes.
🧠 Summary:
-
abs(obj)→ Callsobj.__abs__() -
You must implement
__abs__if you want your custom class to supportabs()
This is part of Python’s data model that allows operator/function overloading.

No comments:
Post a Comment