成员运算符: in not in
name = "郑建文" # 字符串里面的元素叫做字符 # 郑建文字符串 # 建文称为子字符串 # in 表示是否在字符串中 if "郑" in name: print("OK") else: print("Error") name = "郑建文" v = "文" not in name print(v) v = 1==1 print(v) # if "文" not in name # 所以,if后面的条件的结果其实是True or False
布尔值
# 布尔值真or 假 a = True b = False # while True
比较运算符
# == > < >= <= # != 不等于,推荐使用. # <> 不等于
逻辑运算符
# not and v = not False print(v) v = 1 and 1 print(v)
执行顺序
- and 和 or 从左到右计算
- user == 'alex' and pwd=="123" or 1==1
- 结果
- True OR->True
- false or false->false
- true and true=>true
- false and -> false
赋值运算符
count = 1 count += 1 count = count + 1 += -= *= /= **= %= //=