codecamp

Python3 集合 isdisjoint() 方法

Python3 列表 Python 集合

描述

isdisjoint() 方法用于判断两个集合是否包含相同的元素,如果没有返回 True,否则返回 False。。

语法

isdisjoint() 方法语法:

set.isdisjoint(set)

参数

  • set -- 必需,要比较的集合

返回值

返回布尔值,如果不包含返回 True,否则返回 False。

实例

判断集合 y 中是否有包含 集合 x 的元素:

实例 1

x = {"apple", "banana", "cherry"}
y = {"google", "W3Cschool", "facebook"}
 
z = x.isdisjoint(y) 
 
print(z)#不包含返回true

输出结果为:

True

如果包含返回 False:

实例 2

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

输出结果为:

False

Python3 列表 Python 集合


温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

相关教程

Python基础教程

python内置库

python3 math模块

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }