博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python之set集合
阅读量:4356 次
发布时间:2019-06-07

本文共 5431 字,大约阅读时间需要 18 分钟。

一、set集合

不同元素组成的集合,集合的成员被称为集合元素。对象是一组无序排列的值。

二、集合创建与赋值

a.创建

>>>s1 = set()

b.赋值

>>>s1.add(‘Jef’)>>>s1{
'Jef'}

c.访问

>>> s = set('chess')>>> 'h' in sTrue>>> 'a' in sFalse

二、集合类型

set集合类型包括:交集、差集、对称差等。

三、内置函数与方法

def add(self, *args, **kwargs): # real signature unknown        """        Add an element to a set.                This has no effect if the element is already present.        """        pass    def clear(self, *args, **kwargs): # real signature unknown        """ Remove all elements from this set. """        pass    def copy(self, *args, **kwargs): # real signature unknown        """ Return a shallow copy of a set. """        pass    def difference(self, *args, **kwargs): # real signature unknown        """        Return the difference of two or more sets as a new set.                (i.e. all elements that are in this set but not the others.)        """        pass    def difference_update(self, *args, **kwargs): # real signature unknown        """ Remove all elements of another set from this set. """        pass    def discard(self, *args, **kwargs): # real signature unknown        """        Remove an element from a set if it is a member.                If the element is not a member, do nothing.        """        pass    def intersection(self, *args, **kwargs): # real signature unknown        """        Return the intersection of two sets as a new set.                (i.e. all elements that are in both sets.)        """        pass    def intersection_update(self, *args, **kwargs): # real signature unknown        """ Update a set with the intersection of itself and another. """        pass    def isdisjoint(self, *args, **kwargs): # real signature unknown        """ Return True if two sets have a null intersection. """        pass    def issubset(self, *args, **kwargs): # real signature unknown        """ Report whether another set contains this set. """        pass    def issuperset(self, *args, **kwargs): # real signature unknown        """ Report whether this set contains another set. """        pass    def pop(self, *args, **kwargs): # real signature unknown        """        Remove and return an arbitrary set element.        Raises KeyError if the set is empty.        """        pass    def remove(self, *args, **kwargs): # real signature unknown        """        Remove an element from a set; it must be a member.                If the element is not a member, raise a KeyError.        """        pass    def symmetric_difference(self, *args, **kwargs): # real signature unknown        """        Return the symmetric difference of two sets as a new set.                (i.e. all elements that are in exactly one of the sets.)        """        pass    def symmetric_difference_update(self, *args, **kwargs): # real signature unknown        """ Update a set with the symmetric difference of itself and another. """        pass    def union(self, *args, **kwargs): # real signature unknown        """        Return the union of sets as a new set.                (i.e. all elements that are in either set.)        """        pass    def update(self, *args, **kwargs): # real signature unknown        """ Update a set with the union of itself and others. """        pass    def __and__(self, *args, **kwargs): # real signature unknown        """ Return self&value. """        pass    def __contains__(self, y): # real signature unknown; restored from __doc__        """ x.__contains__(y) <==> y in x. """        pass    def __eq__(self, *args, **kwargs): # real signature unknown        """ Return self==value. """        pass    def __getattribute__(self, *args, **kwargs): # real signature unknown        """ Return getattr(self, name). """        pass    def __ge__(self, *args, **kwargs): # real signature unknown        """ Return self>=value. """        pass    def __gt__(self, *args, **kwargs): # real signature unknown        """ Return self>value. """        pass    def __iand__(self, *args, **kwargs): # real signature unknown        """ Return self&=value. """        pass    def __init__(self, seq=()): # known special case of set.__init__        """        set() -> new empty set object        set(iterable) -> new set object                Build an unordered collection of unique elements.        # (copied from class doc)        """        pass    def __ior__(self, *args, **kwargs): # real signature unknown        """ Return self|=value. """        pass    def __isub__(self, *args, **kwargs): # real signature unknown        """ Return self-=value. """        pass    def __iter__(self, *args, **kwargs): # real signature unknown        """ Implement iter(self). """        pass    def __ixor__(self, *args, **kwargs): # real signature unknown        """ Return self^=value. """        pass    def __len__(self, *args, **kwargs): # real signature unknown        """ Return len(self). """        pass    def __le__(self, *args, **kwargs): # real signature unknown        """ Return self<=value. """        pass    def __lt__(self, *args, **kwargs): # real signature unknown        """ Return self
size of S in memory, in bytes """ pass def __sub__(self, *args, **kwargs): # real signature unknown """ Return self-value. """ pass def __xor__(self, *args, **kwargs): # real signature unknown """ Return self^value. """ pass __hash__ = None
方法&函数

 

转载于:https://www.cnblogs.com/jef1025/p/5180503.html

你可能感兴趣的文章
Docker最全教程——数据库容器化(十)
查看>>
浮点数网络传输
查看>>
实现传入两个字符串类型的时间的相减
查看>>
使用Access数据库的几个问题
查看>>
【bzoj1775】[Usaco2009 Dec]Vidgame 电视游戏问题 dp
查看>>
创建servlet程序知识点详解---servlet-day07
查看>>
边工作边刷题:70天一遍leetcode: day 36
查看>>
边工作边刷题:70天一遍leetcode: day 33-1
查看>>
关于字典的小知识
查看>>
《软件工程》课程总结
查看>>
[转] Building xnu for OS X 10.10 Yosemite
查看>>
AC自动机 模板
查看>>
LeetCode Weekly Contest 25
查看>>
好久没玩laravel了,5.6玩下(一)
查看>>
小程序获取微信用户的openid
查看>>
Little Prince
查看>>
我的《大宋王朝》
查看>>
HashMap和HashTable
查看>>
C# is与as
查看>>
查询缓存
查看>>