Python Basic Learning-set Collection

Source: Internet
Author: User
Tags set set

#-*-Coding:utf-8-*-Set set unordered non-repeating sequence

SE = {"A", "B", "C"} #创建SET集合

Print (Type (SE))

Li = [1,2,2,3,4] #转换一个列表成SET Collection

SE1 = Set (LI) print (SE1)

SE2 = set ()

Se2.add (123); Se2.add (567); Print (SE2)



Print (s1.difference (S2)) #取得两个集合元素 Differences

Print (S2.difference (S1))

S3=s1.symmetric_difference (S2) # Get both sides set symmetric difference element

Print (S3)

S1.difference_update (S2) #带更新的功能 updated to S1

Print (S1)

S1.symmetric_difference_update (S2) #带更新功能更新到S1

Print (S1)

S1.discard (one) #移除指定元素 without errors if not included

S1.remove (#移除), if not included will be an error


Print (S3.pop ()) #删除 randomly delete returned objects

Print (s1.intersection (S2)) #取两个集合交集

Print (S1.isdisjoint (S2)) #判断是否有交集

Print (S1.issuperset (S2)) #S1是否包含S2

Print (s1.union (S2)) #并集

S1.update (S2) #添加可迭代的对象

Python Basic Learning-set Collection

Related Article

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