Getters n Setters in Python - Python Step By Step - 16

Опубликовано: 09 Октябрь 2024
на канале: Atif Naseem
3,930
32

In Python, getters and setters are not the same as those in other object-oriented programming languages. Basically, the main purpose of using getters and setters in object-oriented programs is to ensure data encapsulation. Private variables in python are not actually hidden fields like in other object oriented languages. Getters and Setters in python are often used when:

We use getters & setters to add validation logic around getting and setting a value.

To avoid direct access of a class field i.e. private variables cannot be accessed directly or modified by external user.
#PythonTutorial #PythonForBeginners #AtifNaseem