温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》
  • 首页 > 
  • 教程 > 
  • 开发技术 > 
  • 关于简单的运算、二进制运算、逻辑运算符、成员运算符、身份运算符

关于简单的运算、二进制运算、逻辑运算符、成员运算符、身份运算符

发布时间:2020-03-25 17:41:59 来源:网络 阅读:439 作者:pengchunboke 栏目:开发技术

简单的运算

>>> 1+1 

2

>>> 2-1

1

>>> 2*3

6

>>> 2/1

2.0

>>> 5%4     <====返回除法的余数

1

>>> 2**2    <====幂次方

4

>>> 5//2    <====关于取商,只取整数部分

2

>>> 5==5

True

>>> 5!=4    <====关于不等于

True

>>> 5>4

True

>>> 4<5 

True

>>> 5>=5

True

>>> 4<=4

True


关于二进制运算

运算符     描述       实例

&      按位与运算符   10&50得出结果为2  假如A为00001010 B为00110010 就是说A和B中相同的位都为真才为真就是1

|      按位或运算符   10|50得出结果为58 假如A为00001010 B为00110010 就是说A和B中相同的位只要有一位为真才为真就是1

^      按位异或运算符  10^50得出结果为1=56 假如A为00001010 B为00110010 就是说A和B中相同的位只要有一位为真才为真就是1,都为真的话就是假代表0,都为假的话就是假代表0

>>     右移动运算符   假如A为00001010按照右移一位的话结果就是00000101代表5

<<     左移动运算符   假如A为00001010按照左移一位的话结果就是00010100代表5


逻辑运算符

运算符   描述  

and    布尔"与",如果x为false,x and y返回false

or     布尔"或",如果x为true,它就返回true

not    布尔"非",如果x为true,它就返回false


成员运算符

运算符    

in       

not in

举例

the number 1:

name=['alex','rain']
if 'jack' in name:
    print("pengchun is handsome")
else:
    print("pengchun is very handsome")
得出结果pengchun is very handsome

the number 2:

name=['alex','rain']
if 'alex' in name:
    print("pengchun is handsome")
else:
    print("pengchun is very handsome")

 得出结果pengchun is handsome


身份运算符

is  

is not

举例:

the number 1

if type(3) is int:
  print("pengchun is handsome")
得出结果pengchun is handsome

the number 2 
 if type(3) is not list:
    print("pengchun is handsome")
 得出结果pengchun is handsome
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI