ENع
الدرس 19 · Objects

Special (dunder) methods

لم يُترجم بعد؛ يُعرض باللغة الإنجليزية

Why can you write a + b, len(x) or print(x) for your own classes? Because Python turns that ordinary syntax into calls of special methods, the ones named with double underscores. Follow a small Coins class line by line as Coins(3) calls __init__, a + b calls __add__ and print(c) calls __repr__, then see what breaks when a special method is missing.

14 دقيقة9 خطوات5 أسئلةIntermediate
شكل 19 · تفاعلي
جارٍ تحميل الرسم…
أو ← →

اختبار يتاح بعد الخطوة الأخيرة.