首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

Python 入门教程 八 - Python Lists and Dictionaries

2013-09-26 
Python 入门教程 8 ---- Python Lists and Dictionaries 第一节1 介绍了Python的列表list2 列表的式list_n

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]



热点排行