python 笔记5

1、集合:

   并集:

    union(*others)

        返回和多个集合合并后的新的集合

   ’ | ‘运算符重载:等同于union

   update(*others)

        和多个集合合并,就地修改

   ’ |=  ‘等同update

例:a={1,2,3}

  b={2,3,4}

  c=a.union(b)  #或者a|b

>>>{1,2,3,4}  #a和b本身并没有变

  c=a.update(b)

c和a都改变了

   交集:

      intersection(*others)-->返回和多个集合的交集

      ‘ & ’等同于intersection 

      intersection_update(*others)

        获取和多个集合的交集,并就地修改

      ‘ &= ’等同intersection_update

   差集:

      difference(*others)--->返回多个集合的差集

      ‘ - ’等同difference

      difference_update(*others)-->获取和多个集合的差集并就地修改

      ’ -= ‘等同difference——update

   对称差集:集合A和B,由所有不属于A和B的交集元素组成的集合

      symmetric_difference(other)-->返回与另一个集合的差集

      ^ 等同symmetric_difference

      symmetric_difference_update-->获取和另一个集合的差集并就地修改

      ^= 等同symmetric_difference_update

   集合运算:

      issubset(other)、<=  :判断当前集合是否是另一个集合的子集

      set1<set2 :判断set1是否是set2的真子集

      issuperset、>= :判断当前集合是否是other的超集(A是B的子集,B是A的超集)

      set1>set2 :判断set1是否是set的真超集

      isdisjoint(other) :当前集合和另一个集合没有交集;没有交集,返回True

原文地址:https://www.cnblogs.com/mapone/p/12036562.html