7/27 python列表复习
##列表添加元素
borwser = ['baidu','360','2345','QQ','chrom',]
list.append(borwser,'firefox')
print(borwser)
['baidu', '360', '2345', 'QQ', 'chrom', 'firefox']
## 得到列表的总字符串数
print(len(borwser))
6
## 得到列表中最长的字符串
print(max(borwser))
firefox
## 最短的
print(min(borwser))
2345
## 转化为列表
print(list(range(6)))
[0, 1, 2, 3, 4, 5]
##以下标的方式 删除列表元素
borwser.pop(3)
print(borwser)
['baidu', '360', '2345', 'chrom', 'firefox']
## 直接删除列表元素
borwser.remove('360')
print(borwser)
['baidu', '2345', 'chrom', 'firefox']
## 获取列表中元素的下标
print(borwser.index('chrom'))
2
## 列表翻转
borwser.reverse()
print(borwser)
['firefox', 'chrom', '2345', 'baidu']
## 复制列表
borwser1 = borwser.copy()
print(borwser1)
['firefox', 'chrom', '2345', 'baidu']
## 统计列表中出现次数最多的数
print(borwser.count('chrom'))
1
## 在列表中指定位置插入元素
borwser.insert(4,'firefox')
print(borwser)
['firefox', 'chrom', '2345', 'baidu', 'firefox', 'firefox']
## 列表合并
list2 = list(range(6))
borwser.extend(list2)
print(borwser)
['firefox', 'chrom', '2345', 'baidu', 'firefox', 'firefox', 0, 1, 2, 3, 4, 5]