codecamp

Python3 集合 issubset() 方法

Python3 列表 Python 集合

描述

issubset() 方法用于判断集合的所有元素是否都包含在指定集合中,如果是则返回 True,否则返回 False。

语法

issubset() 方法语法:

set.issubset(set)

参数

  • set -- 必需,要比查找的集合

返回值

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

实例

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

实例 1

x = {"a", "b", "c"}
y = {"f", "e", "d", "c", "b", "a"}
 
z = x.issubset(y) 
 
print(z)

输出结果为:

True

如果没有全部包含返回 False:

实例 2

x = {"a", "b", "c"}
y = {"f", "e", "d", "c", "b"}
 
z = x.issubset(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; }