这篇教程python运算符号详细介绍写得很实用,希望能帮到您。
比较运算符
a,b=10,30print('a>b吗?',a>b)print('a<b吗?',a<b)print('a<=b吗?',a>=b)print(a is b)#这个比较的是id标识 a>b吗? Falsea<b吗? Truea<=b吗? FalseFalse 一个变量有三部分组成:1标识,2类型,3值 比较对象的标识使用is
布尔运算符
print(a==1 and b==2)#ture and true-->tureprint(a==1 and b<2)#ture and false-->falseprint(a!=1 and b==2)#false and ture-->falseprint(a!=1 and b!=2)#false and false -->falseprint('---------------or 或者-----------------------------------------')print(a==1 or b==2)#ture or true-->tureprint(a==1 or b<2)#ture or false-->tureprint(a!=1 or b==2)#false or ture-->tureprint(a!=1 or b!=2)#false and false -->falseprint('---------------not 对运算数取反-----------------------------------------')f=Truef2=Falseprint(not f)print(not f2)print('---------------in 与not in-----------------------------------------')s='helloworld'print('w'in s)print('k'in s)print('w'not in s)print('k'not in s) TrueTrueFalseFalseFalse---------------or 或者-----------------------------------------TrueTrueTrueFalse---------------not 对运算数取反-----------------------------------------FalseTrue---------------in 与not in-----------------------------------------TrueFalseFalseTrue
python中的位运算符

运算符的优先级


到此这篇关于python运算符号详细介绍的文章就介绍到这了,更多相关python运算符内容请搜索51zixue.net以前的文章或继续浏览下面的相关文章希望大家以后多多支持51zixue.net! Python中的getattr、__getattr__、__getattribute__、__get__详解 基于深度学习和OpenCV实现目标检测 |