Encapsulation in Python-tccicomputercoaching.com
In an object oriented python program, you can restrict access to methods and variables. This can prevent the data from being modified by accident and is known as encapsulation. Let’s start with an example.
The private attributes and methods are not really hidden, they’re renamed adding “_Car” in the beginning of their name.
Class with private variables. Variables can be private which can be useful on many occasions. A private variable can only be changed within a class method and not outside of the class.
print ‘updating software’
redcar = Car()
#redcar.__updateSoftware() not accesible from object.
This program will output
To learn Encapsulation in Python at TCCI.
Call us @ 98256 18292
Visit us @ http://tccicomputercoaching.com/course/