Skip to content

Latest commit

 

History

History
24 lines (17 loc) · 444 Bytes

36 求两个集合的差集?.md

File metadata and controls

24 lines (17 loc) · 444 Bytes

Python100

把Python知识点整理成100道习题,知识点来自两本书:Python基础教程(第3版)和流畅的Python,以后会定期加入更多的习题,大家帮忙点个赞哈,点赞越多,更新越快~

求两个集合的差集?

解法1:用运算符 -

>>> a = {6, 7, 8}
>>> b = {7, 8, 9}
>>> a-b
{6}

解法2:用 difference 方法

>>> a = {6, 7, 8}
>>> b = {7, 8, 9}
>>> a.difference(b)
{6}