A private method keeps implementation details inside a class so users see only the operations they need. In Python, prefix the method name with two underscores, as in __format_note. section 8.3 section 8.3.2
Use private methods when the class should control an operation’s public visibility:
- Call the private method from other methods inside its class, while exposing a clearer public operation such as complete(). section 8.3.2
- Remember that Python permits deliberate access through the mangled name, such as task._Task__format_note(...); privacy is restrictive rather than absolute. section 8.3.2
- Choose protected methods instead when subclasses should inherit and use the helper; choose private methods when subclasses should not access it. section 8.5.4
Formatting an internal note
class Task:\n def complete(self, note=""):\n self.note = self.__format_note(note)\n\n def __format_note(self, note):\n return note.title()\n\ntask = Task()\ntask.complete("a note")\n# task.note == "A Note" section 8.3.2











