How to use private variable in python class in Tamil | Encapsulation in python #python
In Python, the use of a single underscore (_) and double underscores (__) before attribute names serves as a convention rather than a strict language feature. However, they do have different implications in terms of visibility and name mangling:
Single Underscore Prefix (_age):
This is a convention indicating that the attribute is intended to be "protected" or "private" (though not enforced by the language).
It suggests that the attribute should not be accessed directly from outside the class, but there are no technical restrictions preventing such access.
Double Underscore Prefix (__age):
This triggers name mangling in Python.
Name mangling is a technique to make an attribute "private" to its class.
When you define an attribute with double underscores (__), Python internally changes its name to include the class name as a prefix, making it more difficult to access from outside the class.
However, it's still possible to access these "private" attributes by using the mangled name (_ClassName__attributeName), though this is discouraged because it breaks encapsulation.
Nesta página do site você pode assistir ao vídeo on-line How to use private variable in python class in Tamil | Encapsulation in python duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário pycodedigi 15 Maio 2024, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 217 vezes e gostou 7 espectadores. Boa visualização!