0% found this document useful (0 votes)
7 views9 pages

Access Modifier

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views9 pages

Access Modifier

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Access Modifier

Access Modifier

Access Modifiers:
o Access Modifiers are used to restrict the access of the class member
variable and methods from outside the class.
o Python uses ‘_’ symbol to determine the access control for a specific data
members or a member function of a class.
o Access modifiers in Python have an important role to play in securing data
from unauthorized access and in preventing it from being exploited.
Types of Access Modifiers:
 Public Access Modifiers
 Protected Access Modifiers
 Private Access Modifiers
Access Modifier

Public Access Modifier:


o By default the member variables and methods are public which means
they can be accessed from anywhere outside or inside the class.

o No public keyword is required to make the class or methods and


properties public.
Access Modifier

Example: Output:
Access Modifier

Private Access Modifier:


o Class properties and methods with private access modifier can only be
accessed within the class where they are defined and cannot be
accessed outside the class.

o In python private properties and methods are declared by adding a


prefix with two underscores(‘__’)before their declaration.
Access Modifier

Example: Output:
Access Modifier

Protected Access Modifier:


o Class properties and methods with protected access modifier can be
accessed within the class and from the class that inherits the protected
class.

o In python, protected members and methods are declared using single


underscore(‘_’) as prefix before their names.
Access Modifiers

Example: Output:
Thank You

You might also like