So today I asked if there's something like Protected
member class in Python where many people said there's no something like lik Public
Protected
or Private
. But I made the following code to test this:
class Vehiculo():
def __init__(self, peso):
self.__peso = peso
and from an outer class I did:
car = Vehiculo(10)
car.__peso = 20
and what it printed was still 10, so this is like Private
, however when I changed the class variable with just one underline:
class Vehiculo():
def __init__(self, peso):
self._peso = peso
it printed 20 instead. Can someone clearly explain this to me? I've read a very similar post (that many consider as duplicate) but I DON'T UNDERSTAND what they say. This is exactly the Public
Private
behavior. And I'd like to know how to do a Protected
behavior or if it's even possible.
Thanks and regads.