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.
On this page of the site you can watch the video online How to use private variable in python class in Tamil | Encapsulation in python with a duration of hours minute second in good quality, which was uploaded by the user pycodedigi 15 May 2024, share the link with friends and acquaintances, this video has already been watched 217 times on youtube and it was liked by 7 viewers. Enjoy your viewing!