python条件运算符

来源:互联网 发布:云软件 编辑:程序博客网 时间:2024/05/20 00:12

1. 条件运算符

1.1 ==、<、 <=、 >、 >=、 !=

1.2  x is(not) y #x和y是(不是)同一个对象

1.3 x in(not) y#x是(不是)y容器的成员

1.4 字符串比较根据字母排序进行

2. if not用法

if not condition:    print "condition is False"

3. 断言

当条件为假时直接让程序崩溃,提前暴露错误

assert condition #program will crash when condition is False