zoukankan      html  css  js  c++  java
  • python学习笔记Day3

    set有点:1、访问速度快 2、天生解决了重复问题

    tuple与set区别: 元组可重复,set不可重复
    创捷集合1

    >>> s1.add('alex')
    >>> print(s1)
    {'alex'}
    >>> s1.add('alex')
    >>> print(s1)
    {'alex'}

    创建集合2
    >>> set (['alex','eric','tony'])
    {'tony', 'eric', 'alex'}

    找出不同,并重建一个新的集合
    >>> s1 = set (['alex','eric','tony'])
    >>> s1.diference(['alex','eric'])
    {'tony'}

    >>> s1 = set (['alex','eric','tony'])
    >>> s1.difference(['alex','eric'])
    {'tony'}
    >>> s2=s1.difference(['alex','eric'])


    >>> s2
    {'tony'}
    >>> print(s2)
    {'tony'}


    difference_update 修改原来的集合提出指定的元素

    >>> s1
    {'tony', 'eric'}
    >>> s3 = s1.difference_update(['tony'])
    >>> s1
    {'eric'}

    pop 从原集合拿走一个元素,同时可以用另一个变量接受这个元素。

    >>> s1 = set(['alex','eric','tony'])
    >>> s2 = s1.pop()
    >>> s2
    'alex'
    >>> s1
    {'tony', 'eric'}
    >>>

     

  • 相关阅读:
    动手动脑感想
    原码反码补码
    java测试感想
    报告
    假期报告
    假期报告
    java学习进度
    《大道至简》读后感
    2020/1/31 PHP代码审计之目录穿越漏洞
    [极客大挑战 2019]BabySQL
  • 原文地址:https://www.cnblogs.com/luoye00/p/5176452.html
Copyright © 2011-2022 走看看