# = += -= 赋值运算符号
a = 1
# a = a + 2
a += 2 # 两者是等价的
print(a) # 结果:3
a = 6
# a = a - 2
a -= 2 # 两者是等价的
print(a) # 结果:4
name = "gong"
name += "fu"
print(name) # 字符串的拼接
# and or not 逻辑运算符 真真为真,假假为假
# and 必须两个条件同时满足,只要有一个False,那结果就是假的
a = 5 > 4 # True
b = 3 > 2 # True
c = 6 < 2 # False
print(a and b) # 最终结果也是真 True
print(a and c) # 最终结果也是真 False
# or 两个条件只需要满足一个,只要有一个True,那结果就是真的
a = 5 > 4 # True
b = 3 < 2 # False
c = 6 < 2 # False
print(a and b) # 最终结果也是真 True
print(b and c) # 最终结果也是真 False
# not 与结果相反
a = 4 > 3 # True
print(not a) # 最终结果也是真 False
五、成员运算
# in not in # 成员运算符,是否在某某里面,主要用于在字符串、列表、元组、字典
new_string = "Hello World !"
print("H" in new_string) # 结果:True
print("0" in new_string) # 结果:False
print("0" not in new_string) # 结果:True
六、浮点运算符
# Decimal 用于浮点型的运算 但是用之前一点要把浮点型转化成字符串
from decimal import Decimal
a = 0.1
b = 0.2
C = 0.3
print(a + b) # 计算机的机制,不支持10进制的小数,最终结果:0.30000000000000004
print(Decimal(str(0.1)) + Decimal(str(0.2))) # 最终结果:0.3
print(Decimal(str(0.1)) + Decimal(str(0.2)) == Decimal(str(0.3))) # 结果:True
七、导随机生成数据
import random
print(random.randint(1,100)) # 1-100范围的随机生成一个数据
八、运算符的优先级
# 如果存在多个运算,到底算哪一个
# 我们不需要记优先级,括号的作用在运算当中可以提高优先级
result = (4 > 3) and (len("hello") >9)
print(result) # 结果: False