布尔逻辑运算符
# 布尔逻辑运算符
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
转发评论收藏呦
转发评论收藏呦
转发评论收藏呦
转发评论收藏呦
转发评论收藏呦