python学习之--list

来源:互联网 发布:做问卷调查的软件 编辑:程序博客网 时间:2024/06/06 05:22
#print(dir(list))    #dir()用来查询一个类或者对象所有属性。#print(help(list))   #help()用来查询的说明文档。n = [1,2,5,3,5,2]print(n.count(5))   #list中元素5的个数print(n.index(3))   #list中元素3的下标print(n.pop())      #输出list的弹出的元素(弹出的是最后一个元素)n.remove(5)         #该方法没有返回值但是会移除list中第一个匹配项。print(n)            #输出listn.append(0)         #在list尾端添加元素6          n.sort()            #list排序 ,从小到大print(n)            #输出listn.insert(0,9)       #在下标0出插入元素9print(n)            #输出listprint([1,2,3]+[5,6,9])class superList(list):    def __sub__(self,b):        a = self[:]        b = b[:]        while len(b)>0:            element_b = b.pop()            if element_b in a:                a.remove(element_b)        return a print(superList([1,2,3])-superList([4,3]))


0 0
原创粉丝点击