python 之 运算符 布尔逻辑运算符(Python第七篇)

布尔逻辑运算符

# 布尔逻辑运算符
h = 5
i = 6
j = 0
k = -5
l = -6
m = 0
# 布尔与运算符
if h and i:
    print('正数 and 正数'+str(h and i)+'True')
else:
    print('正数 and 正数' + str(h and i))

if h and j:
    print('正数 and 零'+str(h and j)+'True')
else:
    print('正数 and 零' + str(h and j))

if h and k:
    print('正数 and 负数'+str(h and k)+'True')
else:
    print('正数 and 负数' + str(h and k))

if j and m:
    print('零 and 零'+str(j and m)+'True')
else:
    print('零 and 零' + str(j and m))

if j and k:
    print('零 and 负数'+str(j and k)+'True')
else:
    print('零 and 负数' + str(j and k))

if k and l:
    print('负数 and 负数'+str(l and k)+'True')
else:
    print('负数 and 负数' + str(l and k))

# 布尔或运算符
if h or i:
    print('正数 or 正数' + str(h or i) + 'True')
else:
    print('正数 or 正数' + str(h or i))

if h or j:
    print('正数 or 零' + str(h or j) + 'True')
else:
    print('正数 or 零' + str(h or j))

if h or k:
    print('正数 or 负数' + str(h or k) + 'True')
else:
    print('正数 or 负数' + str(h or k))

if j or m:
    print('零 or 零' + str(j or m) + 'True')
else:
    print('零 or 零' + str(j or m))

if j or k:
    print('零 or 负数' + str(j or k) + 'True')
else:
    print('零 or 负数' + str(j or k))

if k or l:
    print('负数 or 负数' + str(l or k) + 'True')
else:
    print('负数 or 负数' + str(l or k))


# 布尔非运算符
if not(h and i):
    print('正数 not and 正数'+str(not(h and i))+'True')
else:
    print('正数 not and 正数' + str(not(h and i)))

if not(h and j):
    print('正数 not and 零'+str(not(h and j))+'True')
else:
    print('正数 not and 零' + str(not(h and j)))

if not(h and k):
    print('正数 not and 负数'+str(not(h and k))+'True')
else:
    print('正数 not and 负数' + str(not(h and k)))

if not(j and m):
    print('零 not and 零'+str(not(j and m))+'True')
else:
    print('零 not and 零' + str(not(j and m)))

if not(j and k):
    print('零 not and 负数'+str(not(j and k))+'True')
else:
    print('零 not and 负数' + str(not(j and k)))

if not(k and l):
    print('负数 not and 负数'+str(not(l and k))+'True')
else:
    print('负数 not and 负数' + str(not(l and k)))

运行结果

正数 and 正数6True
正数 and 零0
正数 and 负数-5True
零 and 零0
零 and 负数0
负数 and 负数-5True
正数 or 正数5True
正数 or 零5True
正数 or 负数5True
零 or 零0
零 or 负数-5True
负数 or 负数-6True
正数 not and 正数False
正数 not and 零TrueTrue
正数 not and 负数False
零 not and 零TrueTrue
零 not and 负数TrueTrue
负数 not and 负数False

转发评论收藏呦
转发评论收藏呦
转发评论收藏呦
转发评论收藏呦
转发评论收藏呦

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值