python学习笔记---列表(四)

list001=[1,2,3,4,5,5]
'''
for i in list001:
    print(i,end=" ")
输出:1 2 3 4 5
'''
#len(list)列表元素个数
print(len(list001))
#max(list)返回列表中最大值
print(max(list001))
#min()返回列表中最小值
print(min(list001))
#list(sep)
aTuple = (123'Google''Runoob''Taobao')
list1 = list(aTuple)
print ("列表元素 : ", list1)
#list.append()
list001.append("ad")
print(list001)
#list.count(obj)
print(list001.count(5))
#list.extend(seq) 在已存在的列表中添加新的列表内容
#例:
a=[1,2,3,4]
b=[7,8,9,0]
'''
a.extend(b)
print(a)
'''
#list.index()从列表中找出某个值第一个匹配项得索引位置
c=["asd",3,6,7,8,95,34]
print(c.index(6))
#list,insert(index,obj)将对象插入列表中
b.insert(2,"ashd")
print(b)
#list.pop(index=-1)移除列表中一个元素(默认最后一个),并返回该元素得值s
print(a.pop())
print(a)
#list.remove()移除列表中某个值的第一个匹配项
d=[1,2,3,4,5,6,7]
d.remove(2)
print(d)
#list.reverse()反向列表中的元素
d.reverse()
print(d)
#list.sort(key=none,reverse=false)对原列表进行排序;key主要用来进行比较的元素,
#具体的函数的参数就是取自于可迭代对象中,指定可迭代对象中的一个元素来进行排序
#reverse 排序规则,reverse=true降序,reverse=false升序
vowels = ["e","a","u","o","i"]
#降序排列
vowels.sort(reverse=True)
print(vowels)
#升序
vowels.sort(reverse=False)
print(vowels)
#copy()复制列表

 

posted @ 2020-06-12 16:16  黑夜里的月亮  阅读(92)  评论(0编辑  收藏  举报