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)

运行结果

相关推荐
再见晴天*_*2 小时前
SpringBoot 中单独一个类中运行main方法报错:找不到或无法加载主类
java·开发语言·intellij idea
lqjun08273 小时前
Qt程序单独运行报错问题
开发语言·qt
酷飞飞4 小时前
Python网络与多任务编程:TCP/UDP实战指南
网络·python·tcp/ip
hdsoft_huge5 小时前
Java & Spring Boot常见异常全解析:原因、危害、处理与防范
java·开发语言·spring boot
风中的微尘5 小时前
39.网络流入门
开发语言·网络·c++·算法
数字化顾问5 小时前
Python:OpenCV 教程——从传统视觉到深度学习:YOLOv8 与 OpenCV DNN 模块协同实现工业缺陷检测
python
未来之窗软件服务6 小时前
幽冥大陆(二)RDIFSDK 接口文档:布草洗涤厂高效运营的技术桥梁C#—东方仙盟
开发语言·c#·rdif·仙盟创梦ide·东方仙盟
小冯记录编程6 小时前
C++指针陷阱:高效背后的致命危险
开发语言·c++·visual studio
学生信的大叔6 小时前
【Python自动化】Ubuntu24.04配置Selenium并测试
python·selenium·自动化
1uther7 小时前
Unity核心概念⑨:Screen
开发语言·游戏·unity·c#·游戏引擎