SlideShare a Scribd company logo
Python-ENCAPSULATION
Basics about Encapsulation?
Encapsulation is one of the critical features of object-oriented
programming, which involves the bundling of data members and
functions inside a single class. Bundling similar data members and
functions inside a class also helps in data hiding. Encapsulation also
ensures that objects are self-sufficient functioning pieces and can work
independently.
What is Encapsulation?
Encapsulation is one of the cornerstone concepts of OOP. The basic
idea of Encapsulation is to wrap up both data and methods into one
single unit. The way that data and methods are organized does not
matter to the end-user. The user is only concerned about the right way
to provide input and expects a correct output on the basis of the inputs
provided.
Why do we need encapsulation in python?
1. Encapsulation provides well-defined, readable code
2. Prevents Accidental Modification or Deletion
3. Encapsulation provides security
Access Modifier in Python Encapsulation
Sometimes there might be a need to restrict or limit access to certain
variables or functions while programming. There we need an Access
Modifier.
1. Public Member
2. Private Member
3. Protected Member
Python-Encapsulation.pptx
Encapsulation in Python using Public Members
the public modifier allows variables and functions to be accessible from
anywhere within the class and from any part of the program. All
member variables have the access modifier as public by default.
Encapsulation in Python using Private Members
The private access modifier allows member methods and variables to
be accessed only within the class. To specify a private access modifier
for a member, we make use of the double underscore __.
Encapsulation in Python Using Protected Members
What sets protected members apart from private members is that they
allow the members to be accessed within the class and allow them to
be accessed by the sub-classes involved. In Python, we demonstrate a
protected member by prefixing with an underscore _ before its name.
Ad

More Related Content

What's hot (20)

Chapter 07 inheritance
Chapter 07 inheritanceChapter 07 inheritance
Chapter 07 inheritance
Praveen M Jigajinni
 
Wrapper class
Wrapper classWrapper class
Wrapper class
kamal kotecha
 
Python Modules
Python ModulesPython Modules
Python Modules
Soba Arjun
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
Kamal Acharya
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
Nilesh Dalvi
 
Operators in java
Operators in javaOperators in java
Operators in java
AbhishekMondal42
 
Python Datatypes by SujithKumar
Python Datatypes by SujithKumarPython Datatypes by SujithKumar
Python Datatypes by SujithKumar
Sujith Kumar
 
What is Python Lambda Function? Python Tutorial | Edureka
What is Python Lambda Function? Python Tutorial | EdurekaWhat is Python Lambda Function? Python Tutorial | Edureka
What is Python Lambda Function? Python Tutorial | Edureka
Edureka!
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
TMARAGATHAM
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
Sujith Kumar
 
Abstract class in java
Abstract class in javaAbstract class in java
Abstract class in java
Lovely Professional University
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Tech_MX
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
Elizabeth alexander
 
Structures in c++
Structures in c++Structures in c++
Structures in c++
Swarup Kumar Boro
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operator
Jussi Pohjolainen
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
Emertxe Information Technologies Pvt Ltd
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
nitamhaske
 
Interface in java
Interface in javaInterface in java
Interface in java
PhD Research Scholar
 
Type conversion
Type  conversionType  conversion
Type conversion
PreethaPreetha5
 
Python: Polymorphism
Python: PolymorphismPython: Polymorphism
Python: Polymorphism
Damian T. Gordon
 
Python Modules
Python ModulesPython Modules
Python Modules
Soba Arjun
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
Nilesh Dalvi
 
Python Datatypes by SujithKumar
Python Datatypes by SujithKumarPython Datatypes by SujithKumar
Python Datatypes by SujithKumar
Sujith Kumar
 
What is Python Lambda Function? Python Tutorial | Edureka
What is Python Lambda Function? Python Tutorial | EdurekaWhat is Python Lambda Function? Python Tutorial | Edureka
What is Python Lambda Function? Python Tutorial | Edureka
Edureka!
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
TMARAGATHAM
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
Sujith Kumar
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Tech_MX
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operator
Jussi Pohjolainen
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
nitamhaske
 

Similar to Python-Encapsulation.pptx (20)

Understanding Data Abstraction and Encapsulation in Python
Understanding Data Abstraction and Encapsulation in PythonUnderstanding Data Abstraction and Encapsulation in Python
Understanding Data Abstraction and Encapsulation in Python
Julie Bowie
 
Prese00yq3whesfthewgdsyuvferwyjhjdfegcyjgfz.pptx
Prese00yq3whesfthewgdsyuvferwyjhjdfegcyjgfz.pptxPrese00yq3whesfthewgdsyuvferwyjhjdfegcyjgfz.pptx
Prese00yq3whesfthewgdsyuvferwyjhjdfegcyjgfz.pptx
RajshreePathir
 
Lecture 8
Lecture 8Lecture 8
Lecture 8
Debasish Pratihari
 
Presen5416846534653416354165341864adeadvdes
Presen5416846534653416354165341864adeadvdesPresen5416846534653416354165341864adeadvdes
Presen5416846534653416354165341864adeadvdes
RajshreePathir
 
Prese00z213hfcyudegtyfwyyudeqw7tgfi7u.pptx
Prese00z213hfcyudegtyfwyyudeqw7tgfi7u.pptxPrese00z213hfcyudegtyfwyyudeqw7tgfi7u.pptx
Prese00z213hfcyudegtyfwyyudeqw7tgfi7u.pptx
RajshreePathir
 
Presentation related to Encapsulation and OOPs
Presentation related to Encapsulation and OOPsPresentation related to Encapsulation and OOPs
Presentation related to Encapsulation and OOPs
vinitsinghthakur46
 
What is OOP_ (Object Oriented Programming) (1).pptx
What is OOP_ (Object Oriented Programming) (1).pptxWhat is OOP_ (Object Oriented Programming) (1).pptx
What is OOP_ (Object Oriented Programming) (1).pptx
hreempandya
 
OOP interview questions & answers.
OOP interview questions & answers.OOP interview questions & answers.
OOP interview questions & answers.
Questpond
 
OOPS
OOPSOOPS
OOPS
gartaulapratiksha81
 
Object-Oriented Programming in Java.pdf
Object-Oriented Programming in Java.pdfObject-Oriented Programming in Java.pdf
Object-Oriented Programming in Java.pdf
Bharath Choudhary
 
Presentation - Copy no vaperpoit asd.pptx
Presentation - Copy no vaperpoit asd.pptxPresentation - Copy no vaperpoit asd.pptx
Presentation - Copy no vaperpoit asd.pptx
RajshreePathir
 
Reflection in Java
Reflection in JavaReflection in Java
Reflection in Java
Nikhil Bhardwaj
 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interview
Kuntal Bhowmick
 
Features of Object Oriented Programming.pptx
Features of Object Oriented Programming.pptxFeatures of Object Oriented Programming.pptx
Features of Object Oriented Programming.pptx
SwagatoBiswas
 
"Study of Java Access Control Mechanism”
"Study of Java Access Control Mechanism”"Study of Java Access Control Mechanism”
"Study of Java Access Control Mechanism”
IOSR Journals
 
Untitled presentation about object oriented.pptx
Untitled presentation about object oriented.pptxUntitled presentation about object oriented.pptx
Untitled presentation about object oriented.pptx
janetvidyaanancys
 
Basic Concept of Object oriented Programming
Basic Concept of Object oriented ProgrammingBasic Concept of Object oriented Programming
Basic Concept of Object oriented Programming
TusharAneyrao1
 
EEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answerEEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answer
Jeba Moses
 
Basic Concepts of Object Oriented Programming
Basic Concepts of Object Oriented ProgrammingBasic Concepts of Object Oriented Programming
Basic Concepts of Object Oriented Programming
AndiDesign1
 
OOP in Java Presentation.pptx
OOP in Java Presentation.pptxOOP in Java Presentation.pptx
OOP in Java Presentation.pptx
mrxyz19
 
Understanding Data Abstraction and Encapsulation in Python
Understanding Data Abstraction and Encapsulation in PythonUnderstanding Data Abstraction and Encapsulation in Python
Understanding Data Abstraction and Encapsulation in Python
Julie Bowie
 
Prese00yq3whesfthewgdsyuvferwyjhjdfegcyjgfz.pptx
Prese00yq3whesfthewgdsyuvferwyjhjdfegcyjgfz.pptxPrese00yq3whesfthewgdsyuvferwyjhjdfegcyjgfz.pptx
Prese00yq3whesfthewgdsyuvferwyjhjdfegcyjgfz.pptx
RajshreePathir
 
Presen5416846534653416354165341864adeadvdes
Presen5416846534653416354165341864adeadvdesPresen5416846534653416354165341864adeadvdes
Presen5416846534653416354165341864adeadvdes
RajshreePathir
 
Prese00z213hfcyudegtyfwyyudeqw7tgfi7u.pptx
Prese00z213hfcyudegtyfwyyudeqw7tgfi7u.pptxPrese00z213hfcyudegtyfwyyudeqw7tgfi7u.pptx
Prese00z213hfcyudegtyfwyyudeqw7tgfi7u.pptx
RajshreePathir
 
Presentation related to Encapsulation and OOPs
Presentation related to Encapsulation and OOPsPresentation related to Encapsulation and OOPs
Presentation related to Encapsulation and OOPs
vinitsinghthakur46
 
What is OOP_ (Object Oriented Programming) (1).pptx
What is OOP_ (Object Oriented Programming) (1).pptxWhat is OOP_ (Object Oriented Programming) (1).pptx
What is OOP_ (Object Oriented Programming) (1).pptx
hreempandya
 
OOP interview questions & answers.
OOP interview questions & answers.OOP interview questions & answers.
OOP interview questions & answers.
Questpond
 
Object-Oriented Programming in Java.pdf
Object-Oriented Programming in Java.pdfObject-Oriented Programming in Java.pdf
Object-Oriented Programming in Java.pdf
Bharath Choudhary
 
Presentation - Copy no vaperpoit asd.pptx
Presentation - Copy no vaperpoit asd.pptxPresentation - Copy no vaperpoit asd.pptx
Presentation - Copy no vaperpoit asd.pptx
RajshreePathir
 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interview
Kuntal Bhowmick
 
Features of Object Oriented Programming.pptx
Features of Object Oriented Programming.pptxFeatures of Object Oriented Programming.pptx
Features of Object Oriented Programming.pptx
SwagatoBiswas
 
"Study of Java Access Control Mechanism”
"Study of Java Access Control Mechanism”"Study of Java Access Control Mechanism”
"Study of Java Access Control Mechanism”
IOSR Journals
 
Untitled presentation about object oriented.pptx
Untitled presentation about object oriented.pptxUntitled presentation about object oriented.pptx
Untitled presentation about object oriented.pptx
janetvidyaanancys
 
Basic Concept of Object oriented Programming
Basic Concept of Object oriented ProgrammingBasic Concept of Object oriented Programming
Basic Concept of Object oriented Programming
TusharAneyrao1
 
EEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answerEEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answer
Jeba Moses
 
Basic Concepts of Object Oriented Programming
Basic Concepts of Object Oriented ProgrammingBasic Concepts of Object Oriented Programming
Basic Concepts of Object Oriented Programming
AndiDesign1
 
OOP in Java Presentation.pptx
OOP in Java Presentation.pptxOOP in Java Presentation.pptx
OOP in Java Presentation.pptx
mrxyz19
 
Ad

More from Karudaiyar Ganapathy (6)

Python-FileHandling.pptx
Python-FileHandling.pptxPython-FileHandling.pptx
Python-FileHandling.pptx
Karudaiyar Ganapathy
 
Python-exceptionHandling.pptx
Python-exceptionHandling.pptxPython-exceptionHandling.pptx
Python-exceptionHandling.pptx
Karudaiyar Ganapathy
 
Overloading vs Overriding.pptx
Overloading vs Overriding.pptxOverloading vs Overriding.pptx
Overloading vs Overriding.pptx
Karudaiyar Ganapathy
 
Python-Polymorphism.pptx
Python-Polymorphism.pptxPython-Polymorphism.pptx
Python-Polymorphism.pptx
Karudaiyar Ganapathy
 
Python-Classes.pptx
Python-Classes.pptxPython-Classes.pptx
Python-Classes.pptx
Karudaiyar Ganapathy
 
Python-Functions.pptx
Python-Functions.pptxPython-Functions.pptx
Python-Functions.pptx
Karudaiyar Ganapathy
 
Ad

Recently uploaded (20)

Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
Machine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptxMachine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptx
rajeswari89780
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Journal of Soft Computing in Civil Engineering
 
The Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLabThe Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLab
Journal of Soft Computing in Civil Engineering
 
Raish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdfRaish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdf
RaishKhanji
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
Reagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptxReagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptx
AlejandroOdio
 
railway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forgingrailway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forging
Javad Kadkhodapour
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
Avnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights FlyerAvnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights Flyer
WillDavies22
 
15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...
IJCSES Journal
 
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdffive-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
AdityaSharma944496
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)
Vəhid Gəruslu
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
Machine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptxMachine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptx
rajeswari89780
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
Raish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdfRaish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdf
RaishKhanji
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
Reagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptxReagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptx
AlejandroOdio
 
railway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forgingrailway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forging
Javad Kadkhodapour
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
Avnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights FlyerAvnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights Flyer
WillDavies22
 
15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...
IJCSES Journal
 
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdffive-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
AdityaSharma944496
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)
Vəhid Gəruslu
 

Python-Encapsulation.pptx

  • 2. Basics about Encapsulation? Encapsulation is one of the critical features of object-oriented programming, which involves the bundling of data members and functions inside a single class. Bundling similar data members and functions inside a class also helps in data hiding. Encapsulation also ensures that objects are self-sufficient functioning pieces and can work independently.
  • 3. What is Encapsulation? Encapsulation is one of the cornerstone concepts of OOP. The basic idea of Encapsulation is to wrap up both data and methods into one single unit. The way that data and methods are organized does not matter to the end-user. The user is only concerned about the right way to provide input and expects a correct output on the basis of the inputs provided.
  • 4. Why do we need encapsulation in python? 1. Encapsulation provides well-defined, readable code 2. Prevents Accidental Modification or Deletion 3. Encapsulation provides security
  • 5. Access Modifier in Python Encapsulation Sometimes there might be a need to restrict or limit access to certain variables or functions while programming. There we need an Access Modifier. 1. Public Member 2. Private Member 3. Protected Member
  • 7. Encapsulation in Python using Public Members the public modifier allows variables and functions to be accessible from anywhere within the class and from any part of the program. All member variables have the access modifier as public by default.
  • 8. Encapsulation in Python using Private Members The private access modifier allows member methods and variables to be accessed only within the class. To specify a private access modifier for a member, we make use of the double underscore __.
  • 9. Encapsulation in Python Using Protected Members What sets protected members apart from private members is that they allow the members to be accessed within the class and allow them to be accessed by the sub-classes involved. In Python, we demonstrate a protected member by prefixing with an underscore _ before its name.