Python Set difference() 方法

Python 3 教程 · 2019-02-06 18:43:22

描述

difference() 方法用于返回集合的差集,即返回的集合元素包含在第一个集合中,但不包含在第二个集合(方法的参数)中。

语法

difference() 方法语法:

set.difference(set)

参数

  • set -- 必需,用于计算差集的集合

返回值

返回一个新的集合。

实例

返回一个集合,元素包含在集合 x ,但不在集合 y :

实例 1

x = {"apple", "banana", "cherry"} y = {"google", "microsoft", "apple"} z = x.difference(y) print(z)

输出结果为:

{'cherry', 'banana'}

点击查看所有 Python 3 教程 文章: https://codercto.com/courses/l/10.html

查看所有标签

Distributed Algorithms: An Intuitive Approach

Distributed Algorithms: An Intuitive Approach

Wan Fokkink / MIT Press / 2018-2-2 / USD 48.00

The new edition of a guide to distributed algorithms that emphasizes examples and exercises rather than the intricacies of mathematical models. This book offers students and researchers a guide to ......一起来看看 《Distributed Algorithms: An Intuitive Approach》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试