Basic computer course, C programming language, Education, Engineering Course, Engineering Courses, Maths Coaching, online computer coaching, PGDCA course coaching, programming course, school computer coaching, training, Uncategorized, Web Design course

Encapsulation in

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.

class Car:

def __init__(self):


def drive(self):

print ‘driving’

def __updateSoftware(self):

print ‘updating software’

redcar = Car()

#redcar.__updateSoftware() not accesible from object.

This program will output:

updating software


To learn Encapsulation in Python at TCCI.

Call us @ 98256 18292

For more information about programming Language,Computer course, Engineering course

Visit us @


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s