运算符

时间:2020-04-15
本文章向大家介绍运算符,主要包括运算符使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

1.基本运算符

  +  -  *  /  **  %   //

 in    和    not in

name="要向卓"
# "要向卓"是一个字符串  而“要”是一个字符
if "猪" not in name:
    print('yes')
else:
    print("no")

  得到的结果 :yes

‘要向’在字符串中,但'要卓'不在字符串中(补充,全选  ctrl+? 全部注释)

2.补充数据类型  布尔值 :真or假             true   or   false     

if true:     #代表符合条件,永远符合条件

name="要向卓"
# "要向卓"是一个字符串  而“要”是一个字符
if "猪" not in name:
    print('yes')
else:
    print("no")
v="猪" not in name                      #后面时一个判定语句,不是真,就是假,所以赋予他等于一个变量在打印,可以得到布尔值
print(v)

 if 后面跟的条件 的输出布尔值的结果

v=1==2
print(v)
m=3>5
print(m)
a=3!=5
print(a)
v=id=='alex' and pwd=='123'
print(v)

  #and 和 or 的计算逻辑:(一般用括号标记)

从前到后:
  true or ... 结果为真
   true and ... 继续往下判断
   false and... 结果为假
   false or ... 继续往下判断
3.赋值运算符
count=count+1 等价于 count+=1(把加号提前)

原文地址:https://www.cnblogs.com/yxzymz/p/12707109.html