python內置函數5-frozenset()

Help on class frozenset in module __builtin__:


class frozenset(object)

 |  frozenset() -> empty frozenset object

 |  frozenset(iterable) -> frozenset object

 |  

 |  Build an immutable unordered collection of unique elements.

 |  

 |  Methods defined here:

 |  

 |  __and__(...)

 |      x.__and__(y) <==> x&y

 |  

 |  __cmp__(...)

 |      x.__cmp__(y) <==> cmp(x,y)

 |  

 |  __contains__(...)

 |      x.__contains__(y) <==> y in x.

 |  

 |  __eq__(...)

 |      x.__eq__(y) <==> x==y

 |  

 |  __ge__(...)

 |      x.__ge__(y) <==> x>=y

 |  

 |  __getattribute__(...)

 |      x.__getattribute__('name') <==> x.name

 |  

 |  __gt__(...)

 |      x.__gt__(y) <==> x>y

 |  

 |  __hash__(...)

 |      x.__hash__() <==> hash(x)

 |  

 |  __iter__(...)

 |      x.__iter__() <==> iter(x)

 |  

 |  __le__(...)

 |      x.__le__(y) <==> x<=y

 |  

 |  __len__(...)

 |      x.__len__() <==> len(x)

 |  

 |  __lt__(...)

 |      x.__lt__(y) <==> x<y

 |  

 |  __ne__(...)

 |      x.__ne__(y) <==> x!=y

 |  

 |  __or__(...)

 |      x.__or__(y) <==> x|y

 |  

 |  __rand__(...)

 |      x.__rand__(y) <==> y&x

 |  

 |  __reduce__(...)

 |      Return state information for pickling.

 |  

 |  __repr__(...)

 |      x.__repr__() <==> repr(x)

 |  

 |  __ror__(...)

 |      x.__ror__(y) <==> y|x

 |  

 |  __rsub__(...)

 |      x.__rsub__(y) <==> y-x

 |  

 |  __rxor__(...)

 |      x.__rxor__(y) <==> y^x

 |  

 |  __sizeof__(...)

 |      S.__sizeof__() -> size of S in memory, in bytes

 |  

 |  __sub__(...)

 |      x.__sub__(y) <==> x-y

 |  

 |  __xor__(...)

 |      x.__xor__(y) <==> x^y

 |  

 |  copy(...)

 |      Return a shallow copy of a set.

 |  

 |  difference(...)

 |      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.)

 |  

 |  intersection(...)

 |      Return the intersection of two or more sets as a new set.

 |      

 |      (i.e. elements that are common to all of the sets.)

 |  

 |  isdisjoint(...)

 |      Return True if two sets have a null intersection.

 |  

 |  issubset(...)

 |      Report whether another set contains this set.

 |  

 |  issuperset(...)

 |      Report whether this set contains another set.

 |  

 |  symmetric_difference(...)

 |      Return the symmetric difference of two sets as a new set.

 |      

 |      (i.e. all elements that are in exactly one of the sets.)

 |  

 |  union(...)

 |      Return the union of sets as a new set.

 |      

 |      (i.e. all elements that are in either set.)

 |  

 |  ----------------------------------------------------------------------

 |  Data and other attributes defined here:

 |  

 |  __new__ = <built-in method __new__ of type object>

 |      T.__new__(S, ...) -> a new object with type S, a subtype of T

 

class frozenset([iterable])

Return a new frozenset object, optionally with elements taken from iterable. frozenset is a built-in class. See frozenset and Set Types — set, frozenset for documentation about this class.


For other containers see the built-in set, list, tuple, and dict classes, as well as the collections module.


中文說明:

本函數是返回一個凍結的集合。所謂凍結就是這個集合不能再添加或刪除任何集合裏的元素。

它是不可變的,存在哈希值,好處是它可以作爲字典的key,也可以作爲其它集合的元素。缺點是一旦創建便不能更改,沒有add,remove方法。


>>> y=[1,2,3,4,5,6,7,8,9]

>>> print(len(y),y)

(9, [1, 2, 3, 4, 5, 6, 7, 8, 9])

>>> set=frozenset(y)

>>> print(len(set),set)

(9, frozenset([1, 2, 3, 4, 5, 6, 7, 8, 9]))

>>> t=frozenset('bookshop')

>>> t

frozenset(['b', 'h', 'k', 'o', 'p', 's'])

>>> t=frozenset('bookshop')

>>> t

frozenset(['b', 'h', 'k', 'o', 'p', 's'])

>>> for i in t:

...     print(i)

... 

b

h

k

o

p

s


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章