比较python中的两组 [英] Comparing two sets in python

查看:41
本文介绍了比较python中的两组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对比较两组有疑问:

    >>> x = {"a","b","1","2","3"}  
    >>> y = {"c","d","f","2","3","4"}  
    >>> z=x<y        
    >>> print(z)
    False
    >>> z=x>y
    >>> print(z)
    False
     

在上述逻辑中,对于 z=xy.我得到的输出为 False,而表达式之一应返回 True.谁能解释一下为什么?

In the above logic, for both z=x<y and z=x>y. I am getting output as False, whereas one of the expression should return True. Could anyone explain me why?

推荐答案

<> 操作符正在测试严格的 子集.这两个集合都不是另一个集合的子集.

The < and > operators are testing for strict subsets. Neither of those sets is a subset of the other.

{1, 2} < {1, 2, 3}  # True
{1, 2} < {1, 3}  # False
{1, 2} < {1, 2}  # False -- not a *strict* subset
{1, 2} <= {1, 2}  # True -- is a subset

这篇关于比较python中的两组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆