Tabel Atribut di Python
Atribut / Konsep Apa (singkat) Fungsi / Peran Contoh singkat
Instance attribute Properti per objek (`self.x`) Menyimpan state unik tiap [Link] = 'merah'
instance
Class attribute Properti pada kelas (dibagi Nilai bersama / default untuk class Mobil: roda = 4
semua instance) semua objek
Module attribute Variabel/fungsi/kelas dalam Mengorganisir namespace; VERSION = '1.0'
file/module diakses `[Link]`
Method (instance) Fungsi di kelas menerima Perilaku objek (operasi pada def maju(self): ...
`self` instance)
@classmethod Method yang menerima `cls` Operasi terkait kelas, bukan @classmethod def buat(cls):
instance ...
@staticmethod Method tanpa `self`/`cls` Utility terkait kelas tapi tanpa @staticmethod def helper():
akses kelas/instance ...
Special / dunder attrs Metadata & kontrol internal Menyimpan metadata dan obj.__class__, f.__doc__
(`__dict__`, `__class__`, mempengaruhi perilaku
`__name__`, `__doc__`, Python
`__module__`)
__repr__ / __str__ Special methods untuk Menentukan string def __repr__(self): return
representasi debugging (`repr`) / user 'Obj(...)'
(`str`)
__new__ / __init__ `__new__` buat objek, Kontrol pembuatan & def __init__(self, x): self.x = x
`__init__` inisialisasi inisialisasi instance
Descriptors Objek dengan `__get__/__se Mengontrol akses atribut di class D: def __get__(...): ...
t__/__delete__` level kelas (dasar `property`)
property Descriptor praktis Buat method jadi seperti @property def x(self): ...
(getter/setter) atribut dengan kontrol akses
Dynamic access `getattr/setattr/hasattr/delattr` Akses/ubah/hapus atribut setattr(obj, 'a', 10)
secara dinamis (nama string)
__annotations__ Penyimpanan type hints Menyimpan metadata tipe def f(x: int) -> str: ...
(digunakan tools/static
analysis)
Inheritance metadata `__mro__`, `__bases__` Menentukan urutan C.__mro__, C.__bases__
pencarian method/atribut &
base classes
__call__ Special method membuat Membuat objek bisa def __call__(self, *a): ...
instance callable dipanggil seperti fungsi