__repr__ & __str__ dunder methods in Python | OOP repr & str fucntions #kody_az
Dərs haqqında
__repr__ (reprezentasiya)
• __repr__ metodunun əsas məqsədi obyektin dəqiq və texniki baxımdan aydın təsvirini verməkdir.
• Bu metod daha çox proqramçılar və debuq (sazlama) məqsədi üçün nəzərdə tutulub.
⸻
__str__ (sətir kimi təqdimat)
• __str__ metodu obyektin oxunaqlı və istifadəçiyə yönəlik təsvirini təqdim edir.
• print(obj) və ya str(obj) funksiyaları çağırıldıqda bu metod işə düşür.
• Bu nəticə istifadəçiyə göstərilmək üçün nəzərdə tutulur və daha dostyana formatdadır.
Unutmayaq:
__str__ yoxdursa, __repr__ istifadə olunur
__repr__ varsa, str() onu əvəz etmir
========
repr (representation)
• The main purpose of the __repr__ method is to provide a precise and technically clear description of an object.
• This method is primarily intended for programmers and debugging purposes.
⸻
str (string representation)
• The __str__ method provides a readable and user-friendly description of an object.
• This method is triggered when print(obj) or str(obj) is called.
• Its output is designed to be shown to the user in a more friendly and accessible format.
Remember:
If __str__ is not defined, __repr__ is used.
If __repr__ is defined, str() does not override it.
#kody_az #kodyaz #viral #coder #azerbaycan #azerbaijan #baku #baki #programming #kurs #kurslar #course #python #pythonprogramming #oop