以Python 3.x版本为主


  • 逻辑运算符

编号

逻辑运算符

说明

1

and

与运算符,a和b为True,才为True

2

or

或运算符,a和b其中一个为True,则为True

3

not

非运算符,a为False,则为True


  • 代码如下
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Feb 12, 2022 11:00 AM

a=len(str(51))<0
b=len('CTO')>0

print('a值:'+str(a))
print('b值:'+str(b))

# 与运算符
if True:
print('a and b值:'+str(a and b))

# 或运算符
if True:
print('a or b值:'+str(a or b))

# a非运算符
if True:
print('not(a)值:'+str(not(a)))


  • 效果如下

#yyds干货盘点#逻辑运算符 - python基础学习系列(9)_运算符