I am learning to use Python with OOP and when reviewing the concept of encapsulation (define the degree of access and modification of attributes and methods of a class - I understand this concept in this way) I have found information in which it tells me that to define methods and attributes as protected and private you must use "_" and "__" when naming them. for example:
class Mueble:
_marca = "Tecnot"
def __init__(self, tipo, marca, material):
self.tipo = tipo # atributo de tipo público
self._marca = marca # atributo de tipo protegido (solo se puede acceder desde la clase y sus clases hijas)
self.__material = material # atributo de tipo privado (solo se puede acceder desde la clase)
def mostrar_atrib_proteg(self): # método público
return self._marca
def _desarmar(self): # método protegido
print("Se ha desarmado el mueble")
def __romper(self): # método privado
print("Se ha destruido el mueble")
primerMueble = Mueble("silla", "Duramax", "caoba")
print("propiedad pública", primerMueble.tipo) # mostrando un atributo público
print("propiedad protegida", primerMueble._marca) # mostrando un atributo protegido
print("accediendo a la propiedad privada", primerMueble._Mueble__material) # mostrando un atributo privado (a través de la clase)
primerMueble.mostrar_atrib_proteg() # ejecutando un método publico
primerMueble._desarmar() # ejecutando un método protegido
primerMueble._Mueble__romper() # ejecutando un método privado (a través de la clase)
When trying to test the access to the methods and attributes I realized that I could still enter so I looked for information about this and found links like this and this one that indicated that the way to define attributes and methods as protected and private was the way I was using but I found this link (it's in Spanish, my language) in which they explained with examples that the concepts of private and protected attributes do not exist in Python.
At the same time, I have seen that there are questions related to my doubt here and here. And when reviewing the answer to the first one, I see that it is indicated that the concept of private and protected but in the answer (and the question) they present a way defined by the language of how to define something as private.
My question is, how is the concept of encapsulation raised in Python 3?
Obs: I have tried to search the Python 3 documentation for a reference to these concepts but I have not been able to find something that clarifies my doubt.