python13_逻辑比较

逻辑比较

python 复制代码
A = 15
B = 15
C = 25


# 等于比较
def compare1(a, b):
    result1 = (a == b)
    return result1


# 不等比较
def compare2(a, b):
    result2 = (a != b)
    return result2


# 大于比较
def compare3(a, b):
    result3 = (a > b)
    return result3


# 小于比较
def compare4(a, b):
    result4 = (a < b)
    return result4


# 大于或者等于比较
def compare5(a, b):
    result5 = (a >= b)
    return result5


# 小于或者等于比较
def compare6(a, b):
    result6 = (a <= b)
    return result6


# is比较
def compare7(a, b):
    result7 = (a is b)
    return result7


# is not 比较
def compare8(a, b):
    result8 = (a is not b)
    return result8


# or 比较
def compare9(a, b):
    result9 = (a is b) or (a is not b)
    return result9


# and 比较
def compare10(a, b):
    result10 = (a is b) and (a is not b)
    return result10


# not 比较
def compare11(a, b):
    result11 = not (a is b)
    return result11


if __name__ == "__main__":
    print("整型常量A =", A, "整型常量B =", B, "整型常量C =", C)
    print(f"{A} == {B}输出结果为:{compare1(A, B)}")  # A == B
    print(f"{A} != {C}输出结果为:{compare2(A, C)}")  # A != C
    print(f"{A} > {C}输出结果为:{compare3(A, C)}")  # A > C
    print(f"{A} < {C}输出结果为:{compare4(A, C)}")  # A < C
    print(f"{A} >= {C}输出结果为:{compare5(A, C)}")  # A >= C
    print(f"{A} < = {C}输出结果为:{compare6(A, C)}")  # A <= C
    print(f"{A} is {B}输出结果为:{compare7(A, B)}")  # A is B
    print(f"{A} is not {B}输出结果为:{compare7(A, B)}")  # A is not B
    print(f"({A} is {C}) or ({A} is not {B})输出结果为:{compare9(A, B)}")  # (A = C) or(A <>B)
    print(f"({A} is {C}) and ({A} is not {B})输出结果为:{compare10(A, B)}")  # (A = C) and(A <>B)
    print(f"not ({A} is {B})输出结果为:{compare11(A, B)}")  # not (A = B)

运行结果

相关推荐
之歆20 分钟前
Python-正则表达式-信息提取-滑动窗口-数据分发-文件加载及分析器-浏览器分析-学习笔记
python·学习·正则表达式
小庞在加油22 分钟前
Apollo源码架构解析---附C++代码设计示例
开发语言·c++·架构·自动驾驶·apollo
往日情怀酿做酒 V176392963824 分钟前
pytorch的介绍以及张量的创建
人工智能·pytorch·python
豌豆花下猫1 小时前
Python 潮流周刊#110:JIT 编译器两年回顾,AI 智能体工具大爆发(摘要)
后端·python·ai
专注VB编程开发20年1 小时前
各版本操作系统对.NET支持情况(250707更新)
开发语言·前端·ide·vscode·.net
我喜欢就喜欢1 小时前
RapidFuzz-CPP:高效字符串相似度计算的C++利器
开发语言·c++
莫彩1 小时前
【Modern C++ Part7】_创建对象时使用()和{}的区别
开发语言·c++
星光54221 小时前
飞算JavaAI:给Java开发装上“智能引擎”的超级助手
java·开发语言
June bug2 小时前
【Python基础】变量、运算与内存管理全解析
开发语言·python·职场和发展·测试
醇醛酸醚酮酯2 小时前
Qt项目锻炼——TODO(五)
开发语言·qt