Private class methods in Python
I used to work with Java and there were private methods. Is there something like this in Python?
I used to work with Java and there were private methods. Is there something like this in Python?
Python doesn’t support private methods by design. But there is a convention to use a single underscore to point that method is private. You shouldn’t use such methods outside of the class where they are defined. Sometimes programmers mistake name mangling for a tool to make a method private. It uses two underscores before the method name and looks like it hides method for outside the class. But it’s not hide it, only rename. Name mangling uses for class inheritance when we have methods with the same name. You shouldn’t use it for private methods, it’s a bad practice.
There is a detailed explanation for using underscores in this question https://imaginghub.com/forum/posts/1429-double-underscore-vs-single-underscore-before-python-method
Just drop us an email to ... Show more