day06 运算符

1.运算符

num = 9 % 2 # 取余数

number = 9 // 2 #取商

print(num) print(number)

in not in #in 是判断连续的东西是不是在这个里面 name = "郑建文"

if "郑" in name: print("OK") else: print("Error")

成员操作in not in
not in 判断某个东西是否在不在某个东西里边 name = "郑建文" if "文" not in name: print("1") else: print("2")

布尔值:True 真 假False

比较运算符 == 等于 < 小于

大于 = 大于等于 <= 小 != 不等于 <> 不等于

逻辑运算符 and or

#如果前面是真的,OR后面都是真的

#如果前面是false,OR后面继续往下走,如果OR还是false,那么这个就是false user = "alex" pwd = "123" v = user == "alex" and pwd == "123" or 1==1 and pwd == "456" print(v)

执行顺序:

    • 结果
    • True OR ==>True
    • True and ==> 继续走
    • False OR ==>继续走
    • False AND ==>False

猜你喜欢

转载自www.cnblogs.com/styelfang/p/9672035.html
今日推荐