📜  python制作播放器库存 - Python代码示例

📅  最后修改于: 2022-03-11 14:45:36.200000             🧑  作者: Mango

代码示例1
#  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