Python .pptx

N
Access Modifier in python
. Presented by
M.Neya Shree
M.Sc (cs)
Various object-oriented languages like C++, Java,
Python control access modifications which are used to
restrict access to the variables and methods of the
class. Most programming languages has three forms of
access modifiers, which are Public, Protected and
Private in a class.
Python uses ‘_’ symbol to determine the access control
for a specific data member or a member function of a
class. Access specifiers in Python have an important
role to play in securing data from unauthorized access
and in preventing it from being exploited.
A Class in Python has three types of access
modifiers:
● Public Access Modifier
● Protected Access Modifier
● Private Access Modifier
Public Access Modifier:
The members of a class that are
declared public are easily
accessible from any part of the
program. All data members and
member functions of a class are
public by default.
class Geek:
# constructor
def __init__(self, name, age):
# public data members
self.geekName = name
self.geekAge = age
# public member function
def displayAge(self):
# accessing public data member
print("Age: ", self.geekAge)
# creating object of the class
obj = Geek("R2J", 20)
# accessing public data member
print("Name: ", obj.geekName)
# calling public member function of the class
obj.displayAge()
Protected Access Modifier:
The members of a class that are
declared protected are only accessible
to a class derived from it. Data
members of a class are declared
protected by adding a single
underscore ‘_’ symbol before the data
member of that class.
class Student:
# protected data members
_name = None
_roll = None
_branch = None
# constructor
def __init__(self, name, roll, branch):
self._name = name
self._roll = roll
self._branch = branch
# protected member function
def _displayRollAndBranch(self):
# accessing protected data members
print("Roll: ", self._roll)
print("Branch: ", self._branch)
Private Access Modifier:
The members of a class that are declared
private are accessible within the class only,
private access modifier is the most secure
access modifier. Data members of a class
are declared private by adding a double
underscore ‘__’ symbol before the data
member of that class.
class Geek:
# private members
__name = None
__roll = None
__branch = None
# constructor
def __init__(self, name, roll, branch):
self.__name = name
self.__roll = roll
self.__branch = branch
# private member function
def __displayDetails(self):
# accessing private data members
print("Name: ", self.__name)
print("Roll: ", self.__roll)
print("Branch: ", self.__branch)
# public member function
def accessPrivateFunction(self)
# accessing private member function
self.__displayDetails()
# creating object
obj = Geek("R2J", 1706256, "Information Technology")
# calling public member function of the class
obj.accessPrivateFunction()
1 of 10

More Related Content

Similar to Python .pptx

oop lecture 3oop lecture 3
oop lecture 3Atif Khan
78 views23 slides
C++ NotesC++ Notes
C++ NotesMOHAMED RIYAZUDEEN
475 views150 slides

Similar to Python .pptx(20)

chapter-7-classes-and-objects.pdfchapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdf
study material31 views
Class and objectClass and object
Class and object
Prof. Dr. K. Adisesha458 views
oop lecture 3oop lecture 3
oop lecture 3
Atif Khan78 views
C++ NotesC++ Notes
C++ Notes
MOHAMED RIYAZUDEEN475 views
Opp concept in c++Opp concept in c++
Opp concept in c++
SadiqullahGhani1603 views
4 Classes & Objects4 Classes & Objects
4 Classes & Objects
praveenjigajinni1K views
Access specifierAccess specifier
Access specifier
zindadili743 views
C++ classesC++ classes
C++ classes
imhammadali7.9K views
Object oriented approach in python programmingObject oriented approach in python programming
Object oriented approach in python programming
Srinivas Narasegouda743 views
class c++class c++
class c++
vinay chauhan795 views
ClassesClasses
Classes
Sheheryar Gull195 views
Python_Unit_2  OOPS.pptxPython_Unit_2  OOPS.pptx
Python_Unit_2 OOPS.pptx
ChhaviCoachingCenter4 views
11 Inheritance.ppt11 Inheritance.ppt
11 Inheritance.ppt
LadallaRajKumar8 views
inheritanceinheritance
inheritance
Amir_Mukhtar259 views
Inheritance in C++Inheritance in C++
Inheritance in C++
RAJ KUMAR76 views
Class and object in C++ By Pawan ThakurClass and object in C++ By Pawan Thakur
Class and object in C++ By Pawan Thakur
Govt. P.G. College Dharamshala2.1K views
Php oop (1)Php oop (1)
Php oop (1)
Sudip Simkhada195 views
6 Inheritance6 Inheritance
6 Inheritance
praveenjigajinni303 views
C++ presentationC++ presentation
C++ presentation
SudhanshuVijay33.1K views

More from NeyaShree1

WE PPT.pptxWE PPT.pptx
WE PPT.pptxNeyaShree1
4 views7 slides
HDI vs GDI-1.pptxHDI vs GDI-1.pptx
HDI vs GDI-1.pptxNeyaShree1
26 views7 slides
AI and ML.pptxAI and ML.pptx
AI and ML.pptxNeyaShree1
9 views11 slides
IOT.pptxIOT.pptx
IOT.pptxNeyaShree1
12 views8 slides

More from NeyaShree1(12)

WE PPT.pptxWE PPT.pptx
WE PPT.pptx
NeyaShree14 views
HDI vs GDI-1.pptxHDI vs GDI-1.pptx
HDI vs GDI-1.pptx
NeyaShree126 views
AI and ML.pptxAI and ML.pptx
AI and ML.pptx
NeyaShree19 views
IOT.pptxIOT.pptx
IOT.pptx
NeyaShree112 views
Edge detection.pptxEdge detection.pptx
Edge detection.pptx
NeyaShree111 views
Nosql .pptxNosql .pptx
Nosql .pptx
NeyaShree17 views
Cryptography .pptxCryptography .pptx
Cryptography .pptx
NeyaShree16 views
Dos.pptxDos.pptx
Dos.pptx
NeyaShree124 views
Dsa .pdfDsa .pdf
Dsa .pdf
NeyaShree127 views
Dsa .pdfDsa .pdf
Dsa .pdf
NeyaShree111 views
CD.pptxCD.pptx
CD.pptx
NeyaShree179 views

Recently uploaded(20)

BYSC infopack.pdfBYSC infopack.pdf
BYSC infopack.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego160 views
STERILITY TEST.pptxSTERILITY TEST.pptx
STERILITY TEST.pptx
Anupkumar Sharma107 views
Streaming Quiz 2023.pdfStreaming Quiz 2023.pdf
Streaming Quiz 2023.pdf
Quiz Club NITW97 views
discussion post.pdfdiscussion post.pdf
discussion post.pdf
jessemercerail85 views
CWP_23995_2013_17_11_2023_FINAL_ORDER.pdfCWP_23995_2013_17_11_2023_FINAL_ORDER.pdf
CWP_23995_2013_17_11_2023_FINAL_ORDER.pdf
SukhwinderSingh895865480 views
2022 CAPE Merit List 2023 2022 CAPE Merit List 2023
2022 CAPE Merit List 2023
Caribbean Examinations Council3.5K views
Psychology KS4Psychology KS4
Psychology KS4
WestHatch54 views
Dance KS5 BreakdownDance KS5 Breakdown
Dance KS5 Breakdown
WestHatch53 views
231112 (WR) v1  ChatGPT OEB 2023.pdf231112 (WR) v1  ChatGPT OEB 2023.pdf
231112 (WR) v1 ChatGPT OEB 2023.pdf
WilfredRubens.com118 views
GSoC 2024GSoC 2024
GSoC 2024
DeveloperStudentClub1056 views
Universe revised.pdfUniverse revised.pdf
Universe revised.pdf
DrHafizKosar88 views
Class 10 English  lesson plansClass 10 English  lesson plans
Class 10 English lesson plans
TARIQ KHAN189 views
Classification of crude drugs.pptxClassification of crude drugs.pptx
Classification of crude drugs.pptx
GayatriPatra1460 views
ACTIVITY BOOK key water sports.pptxACTIVITY BOOK key water sports.pptx
ACTIVITY BOOK key water sports.pptx
Mar Caston Palacio275 views
ANATOMY AND PHYSIOLOGY UNIT 1 { PART-1}ANATOMY AND PHYSIOLOGY UNIT 1 { PART-1}
ANATOMY AND PHYSIOLOGY UNIT 1 { PART-1}
DR .PALLAVI PATHANIA190 views
AI Tools for Business and StartupsAI Tools for Business and Startups
AI Tools for Business and Startups
Svetlin Nakov74 views

Python .pptx

  • 1. Access Modifier in python . Presented by M.Neya Shree M.Sc (cs)
  • 2. Various object-oriented languages like C++, Java, Python control access modifications which are used to restrict access to the variables and methods of the class. Most programming languages has three forms of access modifiers, which are Public, Protected and Private in a class. Python uses ‘_’ symbol to determine the access control for a specific data member or a member function of a class. Access specifiers in Python have an important role to play in securing data from unauthorized access and in preventing it from being exploited.
  • 3. A Class in Python has three types of access modifiers: ● Public Access Modifier ● Protected Access Modifier ● Private Access Modifier
  • 4. Public Access Modifier: The members of a class that are declared public are easily accessible from any part of the program. All data members and member functions of a class are public by default.
  • 5. class Geek: # constructor def __init__(self, name, age): # public data members self.geekName = name self.geekAge = age # public member function def displayAge(self): # accessing public data member print("Age: ", self.geekAge) # creating object of the class obj = Geek("R2J", 20) # accessing public data member print("Name: ", obj.geekName) # calling public member function of the class obj.displayAge()
  • 6. Protected Access Modifier: The members of a class that are declared protected are only accessible to a class derived from it. Data members of a class are declared protected by adding a single underscore ‘_’ symbol before the data member of that class.
  • 7. class Student: # protected data members _name = None _roll = None _branch = None # constructor def __init__(self, name, roll, branch): self._name = name self._roll = roll self._branch = branch # protected member function def _displayRollAndBranch(self): # accessing protected data members print("Roll: ", self._roll) print("Branch: ", self._branch)
  • 8. Private Access Modifier: The members of a class that are declared private are accessible within the class only, private access modifier is the most secure access modifier. Data members of a class are declared private by adding a double underscore ‘__’ symbol before the data member of that class.
  • 9. class Geek: # private members __name = None __roll = None __branch = None # constructor def __init__(self, name, roll, branch): self.__name = name self.__roll = roll self.__branch = branch # private member function def __displayDetails(self): # accessing private data members print("Name: ", self.__name) print("Roll: ", self.__roll) print("Branch: ", self.__branch) # public member function def accessPrivateFunction(self)
  • 10. # accessing private member function self.__displayDetails() # creating object obj = Geek("R2J", 1706256, "Information Technology") # calling public member function of the class obj.accessPrivateFunction()