美文网首页
python-集合基础

python-集合基础

作者: 水漾涟漪penny | 来源:发表于2019-01-08 18:37 被阅读0次

    #set 集合

    #初始化

    # set1 = {1,'ww',2,3}

    # print(set1)

    #并集 union

    # set1 = {1,'w',2,4,5,6}

    # set2 = {'hah'}

    # set3 = set1.union(set2)

    # print(set3)

    #差集 difference

    # set1 = {1,'w',2,4,5,6}

    # set2 = {1,'235',2,89,5,6}

    # set3 = set1.difference(set2)

    # print(set3)

    # print(set1.difference(set2))

    #交集 intersection

    # set1 = {1,'w',2,4,5,6}

    # set2 = {1,'235',2,89,5,6}

    # set3 = set1.intersection(set2)

    # print(set3)

    #添加add

    # set1 = {1,'w',2,4,5,6}

    # set2 = {1,'235',2,89,5,6}

    # set1.add("!@#")

    # print(set1)

    #删除 discard

    # set1 = {1,'w',2,4,5,6}

    # set2 = {1,'235',2,89,5,6}

    # set2.discard(1)

    # print(set2)

    #清除clear

    # set2 = {1,'235',2,89,5,6}

    # set2.clear()

    # print(set2)

    相关文章

      网友评论

          本文标题:python-集合基础

          本文链接:https://www.haomeiwen.com/subject/dpvbrqtx.html