What is a private method in Python?
Answer
Private methods signal to readers of the code that the methods are/should be used only within the class. So if you want to rename the private method or change its signature, you know that it should be called only from the same class. Thanks to this you know that you won't break calls from other classes, because there should be none.
The word "should" is used intentionally because in Python it is possible to call a private method from outside. However, it is highly recommended not to do so, because the private method communicates: "This method was designed by its author as a method that the others shouldn't be calling.". So if you decide to call it and the author renames it in the future and your code breaks, it is your fault because you ignored a wish of the original author for you not to use the method.
Related Python job interview questions
How do you add a new item to a list in Python?
Python JuniorHow do you display a number of items in a list in Python?
Python JuniorWhy would you use a private method in Python?
Python JuniorHow do you pass an argument to a class constructor in Python?
Python JuniorHow do you define a constructor in a class in Python?
Python Junior