首页 > 代码库 > python基础(week4_day1)

python基础(week4_day1)

本文主要介绍:python中集合的使用,以及一些常用的方法

 1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 # author by lh 4  5 a = set([1, 2, 3, 4, 5]) 6 b = set([4, 5, 6, 7, 8]) 7  8 # 添加 9 a.add(6)10 print(a)11 12 # 添加多个13 a.update([6, 7])14 print(a)15 16 # 删除17 a.remove(7)18 print(a)19 # del a20 21 # 差集22 print(a.difference(b))23 print(a - b)24 25 # 交集26 print(a.intersection(b))27 print(a & b)28 29 # 并集30 print(a.union(b))31 print(a | b)32 33 # 父集34 print(a.issuperset(b))35 print(a > b)36 37 # 子集38 print(a.issubset(b))39 print(a < b)

 

python基础(week4_day1)