OOP Encapsulation in Python | public protected private | class methods attributes | slots #kody_az

Dərs haqqında

Python-da encapsulation (qapalılaşdırma) obyektin daxili vəziyyətini və davranışını gizlətmək, bəzi hissələrinə birbaşa girişə məhdudiyyət qoymaq prinsipidir. Bu, məlumatların təsadüfi dəyişdirilməsinin qarşısını almağa və kodun nizamlı və asan idarə olunan olmasına kömək edir.

Encapsulation Python-da aşağıdakı formada tətbiq olunur:
• Açıq (public) atributlar və metodlar — hər yerdən əlçatandır.
• Qorunan (protected) atributlar — adının əvvəlində tək alt xətt (_) olur və yalnız sinifin içində və ya alt siniflərdə istifadə olunması tövsiyə olunur.
• Gizli (private) atributlar — adının əvvəlində iki alt xətt (__) olur və Python bu adları dəyişdirərək (name mangling) sinifdən kənarda birbaşa istifadənin qarşısını alır.

Python-da bu qaydalar məcburi deyil, amma proqramçılara məlumatları qorumaq və sistemin sabitliyini saxlamaq üçün bu konvensiyalara riayət etmək tövsiyə olunur.

=======

Encapsulation in Python is the principle of hiding the internal state and behavior of an object and restricting direct access to some of its parts. It helps protect data from being accidentally modified and promotes organized, maintainable code.

In Python, encapsulation is achieved through:
• Public attributes and methods, which are accessible from anywhere.
• Protected attributes (with a single underscore), which are intended to be used only inside the class or its subclasses.
• Private attributes (with double underscores), which are name-mangled to prevent unintended access from outside the class.

Although Python does not strictly enforce access restrictions like some other languages, it encourages developers to follow these conventions to keep the internal details of a class hidden and safe from unintended interference.

#python #kody_az #kodyaz #viral #fleet #jetbrains #pycharm #oop #viralcode #viralvideo #random #code #coder #azerbaycan #azerbaijan #azərbaycan #baku #baki #programming #programmer #codes #hazırlıq #hazirliq #kurs #kurslar #course #courses #online #onlinecourses #test #quiz

YouTube-da bax · KODY.AZ