python运算符号详细介绍

2022-01-23

目录
  • 比较运算符
  • 布尔运算符
  • 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

布尔运算符

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 正则表达式大全(推荐)
  • python正则表达式最详解
  • Python 正则表达式详解
  • 详解python的运算符与表达式

《python运算符号详细介绍.doc》

下载本文的Word格式文档,以方便收藏与打印。