3.1 and or not
# 判断变量是否为0, 是0则为False,非0判断为True,
# and中含0,返回0; 均为非0时,返回后一个值,
2 and 0 # 返回0
2 and 1 # 返回1
1 and 2 # 返回2
# or中, 至少有一个非0时,返回第一个非0,
2 or 0 # 返回2
2 or 1 # 返回2
0 or 1 # 返回1
3.2 成员运算符
x = 'abcde'
y = 'a'
y in a //返回true
3.3 身份运算符
用于比较两个对象的存储单元
is, is not
x = 'abc'
y = x
z = 'abcde'
x is y #return true
x is z #return false
a = 'abc'
b = 'abc'
a is b #return true, since that strings are not in stack/heap, but in constant area(not
#sure about the name
3.4 括号运算符
()用来修改优先级
3.5 运算优先级
基本:算术型>关系型>赋值型>逻辑型
3.6 一个小问题
is 与 == 有什么区别?
A: is 是地址指向的比较,==是内容的比较,正好与java相反
3.7 python中的常见三种错误
- 语法错误
- 运行时错误/异常
- 逻辑错误