测量程序编制 - python 48数据类型:Set(集合)-交集.pptxVIP

  • 1
  • 0
  • 约1.09千字
  • 约 8页
  • 2022-04-11 发布于江西
  • 举报

测量程序编制 - python 48数据类型:Set(集合)-交集.pptx

Set(集合)——交集 Set(集合)——交集 集合最常做的操作就是进行交集、并集、差集以及对称差集运算 图 1 中,有 2 个集合,分别为 set1={1,2,3} 和 set2={3,4,5},它们既有相同的元素,也有不同的元素。以这两个集合为例,分别做不同运算的结果 Set(集合)——交集 1、交集 1)运算符 2)intersection() 方法 3)intersection_update() 方法 Set(集合)——交集 1)运算符 set1={1,2,3} set2={3,4,5} set3=set1 set2 print(set3) {3} Set(集合)——交集 2) intersection() 方法:返回两个或更多集合中都包含的元素,即交集 语法: set.intersection(set1, set2 ... etc) set1 -- 必需,要查找相同元素的集合 set2 -- 可选,可以是任何序列,可以多个,多个使用逗号 , 隔开 若是字典,按键比较 返回值:返回一个新的集合 set1={1,2,3} set2={3,4,5,2} list1=[2,3] dict1={2:9,b:10} set3=set1.intersection(set2,list1,dict1) print(set3) {2} Set(集合)——交集

文档评论(0)

1亿VIP精品文档

相关文档