简单的运算

>>> 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'inname:print("pengchunishandsome")else:print("pengchunisveryhandsome")

得出结果pengchunisveryhandsome

the number 2:

name=['alex','rain']if'alex'inname:print("pengchunishandsome")else:print("pengchunisveryhandsome")

得出结果pengchun is handsome


身份运算符

is

is not

举例:

the number 1

iftype(3)isint:print("pengchunishandsome")得出结果pengchunishandsomethenumber2iftype(3)isnotlist:print("pengchunishandsome")得出结果pengchunishandsome