To assign several items in a row to a list, use a range of index numbers. Assigning using a slice follows these rules:
• Python first deletes the items currently assigned to those index numbers and then inserts the new items.
• You don't have to assign the same number of items that you delete.
• You must assign an iterable (see the sidebar, "Gotcha! Assigning numbers and strings to slices").
To assign items to a list slice, follow these steps:
Was this article helpful?