标签:
shoppingList = [‘apple‘,‘banana‘,‘lemon‘,‘juice‘,‘jam‘] print(‘my shopping list is‘,shoppingList) for item in shoppingList: print(item) print("I have",len(shoppingList),‘items to buy‘) shoppingList.append(‘rice‘) print(‘I also have to buy rice‘) print("Now the shopping list is",shoppingList) oldItem = shoppingList[0] del shoppingList[0] print("Now myshopping list is",shoppingList) shoppingList.sort() print("Now my shoppping list is",shoppingList) #总结一下 #1、类似数组,定义时采用数组的定义方法 #2、len(myList)获取长度 #3、sort(myList)排序 #4、del 命令删除项 #5、可以直接用print输出,输出格式为类似数组形式,即定义时候的形式 #6、自身携带append()方法,将值作为方法的参数
2015/4/17
标签:
原文地址:http://www.cnblogs.com/kerita/p/4447939.html