智能小松鼠

## Python逻辑运算符：

and 所谓逻辑与运算符。如果两个操作数都是真的，那么则条件成立。 (a and b) 为 true.
or 所谓逻辑OR运算符。如果有两个操作数都是非零然后再条件变为真。 (a or b) 为 true.
not 所谓逻辑非运算符。用于反转操作数的逻辑状态。如果一个条件为真，则逻辑非运算符将返回false。 not(a and b) 为 false.
``````#!/usr/bin/python

a = 10
b = 20
c = 0

if ( a and b ):
print "Line 1 - a and b are true"
else:
print "Line 1 - Either a is not true or b is not true"

if ( a or b ):
print "Line 2 - Either a is true or b is true or both are true"
else:
print "Line 2 - Neither a is true nor b is true"

a = 0
if ( a and b ):
print "Line 3 - a and b are true"
else:
print "Line 3 - Either a is not true or b is not true"

if ( a or b ):
print "Line 4 - Either a is true or b is true or both are true"
else:
print "Line 4 - Neither a is true nor b is true"

if not( a and b ):
print "Line 5 - Either a is not true or b is not true"
else:
print "Line 5 - a and b are true"``````

```Line 1 - a and b are true
Line 2 - Either a is true or b is true or both are true
Line 3 - Either a is not true or b is not true
Line 4 - Either a is true or b is true or both are true
Line 5 - Either a is not true or b is not true```

http://www.yiibai.com/python/python_basic_operators.html

http://www.runoob.com/python/python-operators.html

http://www.cnblogs.com/linjiqin/p/3608541.html

### 智能小松鼠

QA/测试工程师

2018/05/10
0
0

Mr_zebra
2018/10/08
0
0

选自TowardsDataScience 　　作者：Ehi Aigiomawu 　　机器之心编译 　　参与：李诗萌、路 　　 　　本文介绍了一些 NumPy 基础知识，适合数据科学初学者学习掌握。 　　 　　NumPy（Num...

2018/04/21
0
0
python基础：1. 基础、数据类型

ant_yi
2018/11/13
0
0
《Python从小白到大牛》第7章 运算符

tony关东升
2018/07/16
0
0

24分钟前
1
0

shzwork
26分钟前
2
0
mysql mysql三种插入数据语句和增删改方法

edison_kwok
28分钟前
2
0

39分钟前
1
0

mbzhong
46分钟前
1
0