Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python making player inventory

#  delcare variable as a list using square brackets []
player_inv = []

#  add item to a list with .append()
player_inv.append("item1", "item2")

# remove an item from list with .remove()
player_inv.remove("item1")

#  check if an item is inside a list
if "item1" in str(player_inv):
	print("Yes it's there")

#  print a whole list horizontally
print(player_inv)
    
#  cycle through each item in an inventory and print out a list one item at a time
x2 = 0
for x in player_inv:
	print(str(x2 + 1) + ". " + str(player_inv[x2]))
    x2 += 1
 
PREVIOUS NEXT
Tagged: #python #making #player #inventory
ADD COMMENT
Topic
Name
8+9 =