Python运算符

(1)比较运算符:

<  >  <=  >=  ==  <>(不等于)  !=(不等于)

比较运算符的不等于一般用!=

(2)取值运算符:

+ - * /    **(平方)   //(取除后的整数值)  %(取余)

(3)逻辑运算:

and  or   not 

if name=='lijian' and pwd =='520' :

  print('Nice')

if name=='lijian' and(pwd =='520' or True ) :

有括号先计算括号里的 看真假.

(4)成员操作:

if in     if not in

例 : count=‘李健的博客’   cu='李'           

if cu in count :

  print('OK')

else:

  print('Error')

上述例子输出OK 。

例2: zu='李博客'

if zu not in count:

  print('OK')

else:

  print('Error')

上述例子输出Error.  因为成员判断中只能判断相邻的字符

(5)运算操作:

count+=1等价于count=count+1

此外 还有自减 , 平方等等。

 

posted @ 2018-08-08 11:20  QianruS  阅读(143)  评论(0编辑  收藏  举报