算数运算符: + - * / //(地板除) %(取余) **(幂运算) / 比较运算符 > < >= <= == !=

# ### python运算符
#(1) 算数运算符: + - * / //(地板除) %(取余) **(幂运算)
var1 = 5
var2 = 8

# +
res = var1 + var2 print(res) # - res = var1 - var2 print(res) # * res = var1 * var2 print(res) # /(除法,结果一定是小数) var1 = 8 var2 = 2 res = var1/var2 print(res) # // 地板除(整除) var1 = 8 var2 = 2 res = var1 // var2 print(res) #如果相除的两个含有小数,那么就在结果上加上.0 var1 = 8.0 var2 = 2 res = var1//var2 print(res) # % 取余 print("<========>") var1 = 7 var2 = 4 res = var1 % var2 print(res) print("<==========>") var1 = -7 var2 = 4 res = var1 % var2 print(res) #1 #-3+4 =1 print("<=========>") var1 = 7 var2 = -4 res =var1 % var2 print(res)#-1 #3-4 = -1 # ** (幂运算) var1 = 3 res =var1**3 print(res) # ### 比较运算符 > < >= <= == != '''最终只有两个结果,要么是True 要么是False''' # > var1 = 10 var2 = 20 res = var1 > var2 print(res) # < var1 = 10 var2 = 20 res = var1 < var2 print(res) # >= var1 = 20 var2 = 20 res = var1 >= var2 print(res) # <= var1 = 20 var2 =20 res = var1 <= var2 print(res) # == 等于 var1 = 23 var2 = 21 res = var1 == var2 print(res) ''' 是2个等号,不是1个等号,1个等号是在做变量的赋值,2个是比较是否相同 if var1 == var2 print(123) ''' # != 不等于 var1 = 14 var2 = 13 res = var1 != var2 print(res)

  

上一篇:__init__ 构造方法


下一篇:layer弹窗按钮样式和提示文字内容如何修改?