Private and Public Concepts
Encapsulation provides access to the methods and attributes of the class.
![](https://codefinity-content-media.s3.eu-west-1.amazonaws.com/c5b4ea8f-8a30-439f-9625-ddf2effbd9ac/encapsulation.png)
Private or public
Some attributes and/or methods cannot be accessed or modified. For example, it is correct not to change the number_of_legs
of your cat
object (usually, this value is 4).
This attribute must be private - not available outside the class.
By default, all methods and attributes are public in the Python class.
To make it private, add two __
before the variable name:
The way to access even the private value:
Everything was clear?
Course Content
Object-Oriented Programming in Python
Object-Oriented Programming in Python
1. Classes and Objects
2. Encapsulation
3. Inheritance
4. Polymorphism
Private and Public Concepts
Encapsulation provides access to the methods and attributes of the class.
![](https://codefinity-content-media.s3.eu-west-1.amazonaws.com/c5b4ea8f-8a30-439f-9625-ddf2effbd9ac/encapsulation.png)
Private or public
Some attributes and/or methods cannot be accessed or modified. For example, it is correct not to change the number_of_legs
of your cat
object (usually, this value is 4).
This attribute must be private - not available outside the class.
By default, all methods and attributes are public in the Python class.
To make it private, add two __
before the variable name:
The way to access even the private value:
Everything was clear?