ENع
الدرس 21 · Idiomatic Python

Iterators and generators

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

Every for loop in Python is driven by an iterator: an object that hands out one value per next() call and raises StopIteration when it has no more. A generator is the easiest way to write one: a function with yield in it. Step through countdown.py and watch the generator pause after each yield, keep its local n and its place, carry on exactly where it stopped on the next call, and finish with StopIteration, which the for loop catches quietly.

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

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