2 ms·
There are private and public methods. Private methods are only supposed to be called within other methods, as in privately. Public methods are the ones that are
by freehorse 1y ago
There are private and public methods. Private methods are only supposed to be called within other methods, as in privately. Public methods are the ones that are normally called through the code, repl, by the user or whatever. You are not supposed to write `myclass.__add__(x)` anywhere except where you define the class itself and its methods.
- Izkata 1y agoThere's actually 4 kinds: def foo(... # public def _foo(... # internal def __foo(... # munged def __foo__(... # magic Internal is more convention as the language doesn't really do anything with it, but it does with munged, and magic methods are specifically for things implemented in the language. Internal and munged don't exactly map to private and protected, but are kinda similar ish.
- freehorse 1y agoOh right. I am not really into python, had read some doc about naming conventions some poitns. In any case I actually like how one can use underscores to point on how exposed some method is supposed to be. Makes it simpler to actually know what to skip and what not.