Return to Snippet

Revision: 17151
at August 25, 2009 10:53 by chrisaiv


Updated Code
#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

Revision: 17150
at August 25, 2009 10:53 by chrisaiv


Initial Code
#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

Initial URL

                                

Initial Description
How to concatenate lists, add an item to a list, slice an item from a list.

Initial Title
Python: List Basics

Initial Tags
python

Initial Language
Python