08 python 集合

集合是一个无序不重复元素的序列。
可以使用一下两种方式创建集合:

s = {1,2,3,4,5}

或使用set()函数
set(value)

s2 = set('abcdefgaaaaa')

输出

s2:  {'c', 'd', 'b', 'g', 'a', 'e', 'f'}  #无序不重复

集合的内置函数方法

>>> dir(set)
['__and__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__iand__', '__init__', '__init_subclass__', '__ior__', '__isub__', '__iter__', '__ixor__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__or__', '__rand__', '__reduce__', '__reduce_ex__', '__repr__', '__ror__', '__rsub__', '__rxor__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__xor__', 'add', 'clear', 'copy', 'difference', 'difference_update', 'discard', 'intersection', 'intersection_update', 'isdisjoint', 'issubset', 'issuperset', 'pop', 'remove', 'symmetric_difference', 'symmetric_difference_update', 'union', 'update']

未完待续······

猜你喜欢

转载自blog.csdn.net/qq_42397914/article/details/81430318