python----运算符、布尔值
一、运算符: + - * / ** // %
1,、 in ,not in 用法(判断某个东西是否在某个东西里面)
name = '郑建文' 其中‘郑建文’是字符串, ‘郑’或‘建’或‘文’是一个字符 ‘郑健’或‘建文’是子字符、又叫子序列(必须连续) 禁忌:不能用‘郑文’
name='郑建文' if '郑' in name: print ('ok') else: print ('error') if '建文' in name: print('1') else: print('2')
2、赋值运算:
1 count=1 2 count=count+1 可简写为: count+=1 3 count=count-1 count-=1 4 count=count*1 count*=1 5 count=count/1 count/=1 6 count=count**1 count**=1 7 count=count%1 count%=1 8 count=count//1 count//=1
二、数据类型-----布尔值
布尔值只有两个值:真(True),假(False) 首字母大写
name = '郑建文' v = ‘文’ in name: print (v) 结果为true 还可以用来表示 v = 1 == 2: print (v) 结果为false 因此可以进行以下比较: > < = >= <= != <>不等于
补充: v = user =='ales' and (pwd=='123' or 1==1) 系统会优先计算括号内的内容,若没有括号:系统会按顺序执行操作
补充:
“ ” 空字符串为false
“sfd” 字符串中有东西为true
数字0为false
其他数字为true