Tên có dạng __name__ (dunder - double underscore) được dành riêng cho Python built-in (special/magic methods).
Ví dụ phổ biến
__init__: Khởi tạo instance.__str__,__repr__: String representation.__len__:len(obj).__getitem__:obj[key].__call__: Cho phép instance gọi như functionobj().__enter__,__exit__: Context manager (with).__add__,__eq__...: Operator overloading.
Quy tắc đặt tên (PEP 8)
- Không tự đặt tên bắt đầu và kết thúc bằng
__(trừ khi implement protocol). _single_leading: Weak internal use (convention).__double_leading: Name mangling (class private).__dunder__: Reserved cho Python.
Lưu ý: Python không enforce private, chỉ convention và name mangling (_ClassName__attr).