
Task 3 – The Delivery MAN – Python List
1.Create a list of five delivery items and print the third item in the list. eg: [“Notebook”, “Pencil”, “Eraser”, “Ruler”, “Marker”] CODE: items = ["Notebook", "Pencil", "Eraser", "Ruler", "Marker"] print(items[2]) OUTPUT: Eraser EXPLANATION: List indexing starts from 0 Third item → index 2 2.A new delivery item “Glue Stick” needs to be added to the list. Add it to the end of the list and print the updated list. CODE: items = ["Notebook", "Pencil", "Eraser", "Ruler", "Marker"] items.append("Glue Stick") print(items) OUTPUT: ['Notebook', 'Pencil', 'Eraser', 'Ruler', 'Marker', 'Glue Stick'] EXPLANATION: append() adds item to the end 3.Insert “Highlighter” between the second and third items and print the updated list. CODE: items = ["Notebook", "Pencil", "Eraser", "Ruler", "Marker", 'Glue Stick'] items.insert(2, "Highlighter") print(items) OUTPUT: ['Notebook', 'Pencil', 'Highlighter', 'Eraser', 'Ruler', 'Marker', 'Glue Stick'] EXPLANATION: insert(index, value) adds at specific position 4.
Continue reading on Dev.to Tutorial
Opens in a new tab




