بناء قائمة وتوسيعها
أضف إلى List وافهرسها وكرّر عليها
بناء قائمة وتوسيعها درس مجاني في Mojo Academy على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Mojo Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Mojo Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Why a List?
When you need an ordered, growable group of values, reach for a List. It holds items in sequence and can stretch as you add. 📋
A Typed Container
A Mojo List is typed: every element shares one type, like List[Int]. That uniformity is what makes it fast.
var nums = List[Int]()Start Empty
Calling List[Int]() gives you an empty list ready to fill. The type in brackets says what it will store.
var scores = List[Int]()Append an Item
Add a value to the end with append. Each call grows the list by one, keeping insertion order.
scores.append(90)
scores.append(85)Read by Index
Reach an element with square brackets and its position. Indexing is zero-based, so the first item is at 0.
var first = scores[0]How Many Items
Ask a list its size with len. It returns the current count, which changes as you append or remove.
var n = len(scores)Change an Element
Assign through an index to replace a value in place. The list stays the same length; only that slot updates.
scores[0] = 100Iterate the Items
Walk a list with a for loop. It hands you each element directly, so you rarely manage indices yourself.
for s in scores:
print(s)Build From a Literal
You can fill a list at creation with a list literal. Mojo infers the element type from the values you give.
var fruits = List[String]("apple", "pear")Remove From the End
Drop the last item with pop. It shrinks the list and hands back the value you removed.
var last = scores.pop()Lists Grow on the Heap
A list stores its elements on the heap, so it can resize freely as you append. That flexibility is its superpower.
Quick Check
You have an empty List[Int] and call append three times. What is len of the list afterward?
Recap
A List is an ordered, typed, growable container. Use append to add, brackets to index, and len to count. 🎯
الأسئلة الشائعة
هل درس «بناء قائمة وتوسيعها» مجاني؟
نعم — نص درس «بناء قائمة وتوسيعها» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Mojo Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Mojo Academy 4 دروس في المجموع.
ماذا ستتعلم في «بناء قائمة وتوسيعها»؟
أضف إلى List وافهرسها وكرّر عليها تتمرن على Mojo Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Mojo Academy؟
لا تُشترط خبرة سابقة. Mojo Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.
كم من الوقت يستغرق درس «بناء قائمة وتوسيعها»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Mojo Academy هذا؟
نعم. كل درس في Mojo Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- بناء قائمة وتوسيعها
- بيانات المفتاح والقيمة باستخدام Dict
- العناصر الفريدة باستخدام Set
- اختيار مجموعة البيانات المناسبة