python 示例_Python Set isdisjoint()方法与示例

python 示例

设置isdisjoint()方法 (Set isdisjoint() Method)

isdisjoint() method is used to check whether elements are common in two sets or not, method is called with one set (commonly known as this set) and another set is supplied as an argument, method returns "True" if none of the elements are common in both sets, else it returns "False".

isdisjoint()方法用于检查元素在两个集合中是否通用,用一个集合(通常称为此集合)调用方法,并提供另一个集合作为参数,如果没有元素,则方法返回“ True”在这两个集合中都是相同的,否则返回“ False”。

Syntax:

句法:

    set1.isdisjoint(set2)

Parameter(s):

参数:

  • set1 – It represents the set1 (this set).

    set1 –代表set1(此set)。

  • set2 – It represents the set2 (another set to be compared).

    set2 –代表set2(另一个要比较的集合)。

Return value:

返回值:

The return type of this method is <class 'bool'>, it returns a Boolean value (True or False).

此方法的返回类型为<class'bool'> ,它返回一个布尔值(True或False)。

Example 1:

范例1:

# Python Set isdisjoint() Method with Example

# declaring the sets
cars_1 = {"Porsche", "Audi", "Lexus"}
cars_2 = {"Porsche", "Mazda", "Lincoln"}
cars_3 = {"BMW", "Mazda", "Lincoln"}

# isdisjoint() method call
result = cars_1.isdisjoint(cars_2)
print("cars_1.isdisjoint(cars_2): ", result)

result = cars_2.isdisjoint(cars_3)
print("cars_2.isdisjoint(cars_3): ", result)

result = cars_1.isdisjoint(cars_3)
print("cars_1.isdisjoint(cars_3): ", result)

Output

输出量

cars_1.isdisjoint(cars_2):  False
cars_2.isdisjoint(cars_3):  False
cars_1.isdisjoint(cars_3):  True

Example 2:

范例2:

# Python Set isdisjoint() Method with Example

# declaring the sets
x = {"ABC", "PQR", "XYZ"}
y = {"ABC", "PQR", "XYZ"}
z = {"DEF", "MNO", "UVW"}

# isdisjoint() method calls
result = x.isdisjoint(y)
print("x.isdisjoint(y): ", result)

result = y.isdisjoint(z)
print("y.isdisjoint(z): ", result)

result = z.isdisjoint(x)
print("z.isdisjoint(x): ", result)

result = x.isdisjoint(z)
print("x.isdisjoint(z): ", result)

result = y.isdisjoint(x)
print("y.isdisjoint(x): ", result)

Output

输出量

x.isdisjoint(y):  False
y.isdisjoint(z):  True
z.isdisjoint(x):  True
x.isdisjoint(z):  True
y.isdisjoint(x):  False


翻译自: https://www.includehelp.com/python/set-isdisjoint-method-with-example.aspx

python 示例

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值