Python 入门教程 8 ---- Python Lists and Dictionaries
第一节
1 介绍了Python的列表list
2 列表的格式list_name = [item1 , item2],Python的列表和C语言的数组很像
3 列表可以为空,就是empty_list = [],比如数组为空
4 举例
# Assigned a new list to 'pouch' keyinventory = {'gold' : 500,'pouch' : ['flint', 'twine', 'gemstone'], 'backpack' : ['xylophone','dagger', 'bedroll','bread loaf']}# Adding a key 'burlap bag' and assigning a list to itinventory['burlap bag'] = ['apple', 'small ruby', 'three-toed sloth']# Sorting the list found under the key 'pouch'inventory['pouch'].sort() # Here the dictionary access expression takes the place of a list name # Your code hereinventory['pocket'] = ["seashell" , "strange berry" , "lint"]inventory['pocket'].sort()del inventory['backpack']inventory['gold'] = [500 , 50]