Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the six operation schemes of collection types in Python dictionary?

Shulou Source: shulou.com Published: 2022-06-02 23:29:36 10月01日 Update

What are the six operation schemes of collection types in the Python dictionary? many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can get something.

Collection type

① uses the collection's factory methods set () and frozenset ():

> s = set ('cheeseshop') > s set ([' bookshop', 'bookshop']) > > t = frozenset (' bookshop') > t frozenset (['baked,' hacked, 'kink,' type,']) > > type (s) > type (t)

How ② updates a collection adds and removes members of the collection using various collection built-in methods and operators:

> s.add ('z') > s set (['cased,' estranged, 'hacked,' oiled, 'paired,' sworn,'z']) > > s.update ('pypi') > s set ([' clocked, 'estranged,' set, 'hogwash,' oval, 'pendant,' s.remove,'z']) > > s set (['c']) ) > > s-= set ('pypi') > s set ([' cased, 'estranged,' hacked, 'oval,' s'])

③ delete collection

Del s

④ membership (in, not in)

> s = set ('cheeseshop') > t = frozenset (' bookshop') >'k'in s False >'k'in t True >'c 'not in t True

⑤ set equivalence / non-equivalence

> s = = t False > s! = t True > u = frozenset (s) > s = = u True > set ('posh') = = set (' shop') True

⑥ difference complement / relative complement set (-) the difference complement or relative complement set of two sets (s and t) refers to a set C in which the elements belong only to the set s, not to

In the set t. There is an equivalent method for subtraction.

Difference (). > s-t set (['censor,' e'])

Symmetric difference (^): symmetric difference is the XOR of a set. The above article is the practical application step of the Python dictionary to the set type.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Tags: Type method dictionary symmetry member article equivalence help scheme central set clear two element content actual for this that is factory operator novice Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info OPPO Reno Shulou Information Redmi Apple