طول الشريحة وسعتها
طول الشريحة وسعتها
للشريحة كلٌّ من طول وسعة.
طول الشريحة هو عدد العناصر التي تحتوي عليها.
سعة الشريحة هي عدد العناصر في المصفوفة التي تستند إليها، بدءًا من العنصر الأول في الشريحة.
يمكن الحصول على طول الشريحة s وسعتها باستخدام التعبيرين
len(s) وcap(s).
يمكنك زيادة طول الشريحة بإعادة تحديد شريحة منها، بشرط أن تكون لها سعة كافية. جرّب تغيير إحدى عمليات الشرائح في البرنامج المثال لتمديدها إلى ما يتجاوز سعتها، وانظر ماذا يحدث.
النص الأصلي بالإنجليزية
Slice length and capacity
A slice has both a length and a capacity.
The length of a slice is the number of elements it contains.
The capacity of a slice is the number of elements in the underlying array, counting from the first element in the slice.
The length and capacity of a slice s can be obtained using the expressions
len(s) and cap(s).
You can extend a slice's length by re-slicing it, provided it has sufficient capacity. Try changing one of the slice operations in the example program to extend it beyond its capacity and see what happens.
هذا الدرس للقراءة فقط؛ جرّب المثال في الدرس التالي.