python运算符号怎么用

这篇文章给大家分享的是有关python运算符号怎么用的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

比较运算符

python运算符号怎么用

a,b=10,30
print('a>b吗?',a>b)
print('a<b吗?',a<b)
print('a<=b吗?',a>=b)
print(a is b)#这个比较的是id标识
a>b吗? False
a<b吗? True
a<=b吗? False
False

一个变量有三部分组成:1标识,2类型,3值
比较对象的标识使用is

布尔运算符

python运算符号怎么用

print(a==1 and b==2)#ture and true-->ture
print(a==1 and b<2)#ture and false-->false
print(a!=1 and b==2)#false and ture-->false
print(a!=1 and b!=2)#false and false -->false
print('---------------or 或者-----------------------------------------')
print(a==1 or b==2)#ture or true-->ture
print(a==1 or b<2)#ture or false-->ture
print(a!=1 or b==2)#false or ture-->ture
print(a!=1 or b!=2)#false and false -->false
print('---------------not 对运算数取反-----------------------------------------')
f=True
f2=False
print(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)
True
True
False
False
False
---------------or 或者-----------------------------------------
True
True
True
False
---------------not 对运算数取反-----------------------------------------
False
True
---------------in 与not in-----------------------------------------
True
False
False
True

python中的位运算符

python运算符号怎么用
python运算符号怎么用

运算符的优先级

python运算符号怎么用
python运算符号怎么用

感谢各位的阅读!关于“python运算符号怎么用”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!