/ Published in: Python
How to concatenate lists, add an item to a list, slice an item from a list.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#List #1 inventory = ["sword", "armor", "shield", "healing potion"] #List #2 chest = ["gold", "gems"] #For Loop for item in inventory: print item #Concatenating Lists inventory += chest print len(inventory) #Adding New Items to the List inventory[4:4] = "chrisaiv" #Assigning a New List Slice inventory[0:1] = ["rocks"] print inventory #Delete a List Slice del inventory[4:9] print inventory