Python学习笔记(十)Python运算符

1.基本运算

 +   -   *   /   %取余   //取商  **幂

2.其他运算

   字符相关

  成员操作运算符

  判断某个东西是否在某个东西里面

    in  not in

  子序列(子字符串)必须连续才正确,非连续判断都是ERROR

#!/usr/bin/env python
#-*-coding:utf8-*-
name="郑建文"
if "正" in name:
    print("ok")
else:
    print("error")

3. 布尔值
布尔值:True真 False假

if True:
  if 1==1:

v="文" not in name
if v :
  print(111)
4. 比较运算符
==
>
<
>=
<=
!=不等于
<>不等于
not 非

  注意:整体注释,选中后按住ctrl+?

  5. 逻辑运算符

  and

   or

user="alex"

pwd="123"

user=="alex" and pwd=="123" or 1==1 and pwd=="9962"

 执行顺序有括号先括号,无括号依次执行

True or ====>True

True and ====>继续执行

False or ====>继续执行

False and ====>False

6.赋值运算符

  coun=coun+1===>coun+=1

 coun=coun-1====>coun-=1

 coun=coun*1====>coun*=1

coun=coun/1====>coun/=1

coun=coun//1====>coun//=1

 

 

 

  

posted @ 2019-02-16 14:07  魅力无法挡  阅读(156)  评论(0编辑  收藏  举报