列表 -- 常用方法
# len()方法:列表元素个数
abc = ["to","ad","dge","to","buy","be"]
num = len(abc)
print(num)
# count方法:计算某元素出现次数
abc = ["to","ad","dge","to","buy","be"]
num = abc.count("to")
print(num)
#extend方法:继承
a = [1,2,3]
b = [4,5,6]
a.extend(b)
print[a]
#index方法:查找元素所在位置
abc = ["to","ad","dge","to","buy","be"]
abc.index("dge")
#reverse方法:列表内容反转(该方法没有返回值)
abc = ["to","ad","dge","to","buy","be"]
abc.reverse()
print(abc)
#sort方法:排序(当排序的内容不为数字时,默认按照ASK码先后进行排序)
abc = [3,5,1,6,8,2,9]
x.sort()
#enumerate方法:显示列表序号和列表内容
注:enumerate(列表元素,元素编号起始值)
Goods_list = [["iphoneX", 5800], ["mac book", 12000], ["coffee", 30], ["python book", 15], ["bike", 2000]]
for i , v in enumerate(Goods_list , 1):
print(i , v)