📚 › Python: the friendliest first language
6. Slicing lists
ستتم ترجمة هذا المقال تلقائيًا. يُعرض بالإنجليزية حاليًا.
A slice takes part of a list: items[1:3] gives items at positions 1 and 2, because the end is not included. items[:2] starts at the beginning, and items[-1] is the last item.
Slicing never changes the original list.
عرض المثال
letters = ["a", "b", "c", "d"]
print(letters[1:3])
print(letters[-1])
✍️ دورك الآن
From [10, 20, 30, 40, 50], print the middle three items as a list.