Python collection type built-in method summary

Source: Internet
Author: User

 
Collection (s). Method name Equivalent symbol Method description
S.issubset (t) S <= t Subset testing (allows for a subset of non-strict meanings): All elements in S are members of T
S < T Subset testing (STRICTLY): s! = T and all elements in s are members of T
S.issuperset (t) S >= t Hyper-set test (allows for non-strict superset): All elements in T are members of S
s > t Hyper-Set testing (STRICTLY): s! = T and all elements in T are members of S
S.union (t) s | T Merge operation: Elements in S "or" t
S.intersection (t) S & T Intersection operations: Elements in S "and" t
S.difference S-t Differential operation: An element that exists in s that does not exist in T
S.symmetric_difference (t) s ^ t Symmetric differential operation: elements in S "or" T, but not elements common to s and T
S.copy () Returns a copy of S (Shallow copy)
The following methods apply only to mutable collections
S.update S |= t Add an element from T to S
S.intersection_update (t) S &= t Intersection modification operation: s includes only members of S and T
S.difference_update (t) S-= t Difference modification operation: s includes members that belong only to s but are not part of T
S.symmetric_difference_update (t) S ^= t Symmetric differential modification operation: s includes only members belonging to s or only t
S.add (obj) Add an action: adding obj to S
S.remove (obj) Delete operation: Removes obj from S and throws an exception if obj does not exist in S
S.discard (obj) Discard operation: Remove obj from S, and if obj is not present in S, it's okay ^_^
S.pop () Eject action: Remove and return any element in S
S.clear () Clear action: Clears all elements in s

Python collection type built-in method summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.