When you create objects, you are creating an API. You are giving that object attributes and methods that the outside world can interact with. car.drive()
, horse.color
, etc.
In the real world, the implementation of a class requires that you create a lot of methods specifically to make the class work, and are not part of this exposed API. Maybe you need a method called "honk", but you don't want it to be used anywhere except within your own code.
It is these internal methods that we consider to be "private". Some programming languages have formal constructs for making public or private methods. Python does not. However, by convention, methods and attributes that begin with an underscore are to be treated as private.
Just about every experienced python programmer, when seeing a method with an underscore, knows not to call it from anywhere outside of the class definition. They can, but they normally don't.
Why would you want some things to be private? One reason is that code changes. You add parameters, you remove parameters, you change algorithms. The public interface is something that doesn't normally change much once it's created. You may add to it, but you don't usually make big changes.
Private methods, by nature of being "hands off" to the outside world, can be freely changed without worrying about what other parts of the code may be calling those functions.