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)

运行结果

相关推荐
热爱生活的五柒几秒前
在有真实标签 (Ground Truth) 的情况下,常用的指标有哪些?聚类指标有哪些?
python·指标
5980354151 分钟前
【java工具类】小数、整数转中文小写
android·java·开发语言
superman超哥1 分钟前
仓颉语言智能指针深度实战:突破 GC 与所有权的边界
c语言·开发语言·c++·python·仓颉
cike_y2 分钟前
Mybatis之作用域(Scope)和生命周期-解决属性名和字段名不一致的问题&ResultMap结果集映射
java·开发语言·数据库·tomcat·mybatis
捻tua馔...2 分钟前
mobx相关使用及源码实现
开发语言·前端·javascript
Elaine33611 分钟前
【基于 Scikit-learn 本地数据集的垂直领域词云生成】
python·机器学习·nlp·scikit-learn·词云
38242782712 分钟前
python:mysql数据库
数据库·python·mysql
中科院提名者16 分钟前
KNN实战进阶:模型评估、Scikit-learn实现与Numpy手动编码
python·numpy·scikit-learn
2401_8414956420 分钟前
【LeetCode刷题】杨辉三角
数据结构·python·算法·leetcode·杨辉三角·时间复杂度·空间复杂度
微爱帮监所写信寄信21 分钟前
微爱帮监狱寄信写信小程序与焦作邮政系统对接技术方案
开发语言·网络协议·小程序·https·php·监狱寄信