python基础

运算符

1、算数运算: +,-,*,/,%,**,//

print (3+2) => 5print (3-2) => 1print (2*4) => 8print (9/3) => 3print (2**2) => 4print (100%51) => 49print (9//2) => 4

2、比较运算: ==,!=,,>,=, falseprint (3!=2) => trueprint (24) => true #python3.5中已经取消,整合至!=print (9>3) => trueprint (2 falseprint (100>=51) => trueprint (9 false

3、赋值运算: =,+=,-=,*=,/=,%=,**=,//=

a = 5print (a) => 5a = 5b = 1b += a # b=b+aprint (b) => 6a = 5b = 1b -= a # b=b-aprint (b) => -4a = 5b = 1b *= a # b= b*aprint (b) => 5a = 5b = 1b /= a # b = b/aprint (b) => 0.2a = 5b = 1b **= a # b = b**aprint (b) => 1a = 5b = 1b %= a # b = b%aprint (b) => 1a = 5b = 1b //= a # b = b//aprint (b) => 0

4、逻辑计算: and, or ,not

a = trueb = falseprint (a and b) => false # 只有a,b均为真时,才为真print (a or b) => true # 只要a,b中有一个为真时,就为真print (not a) => false # 非真print (not b) => true # 非假

5、成员运算: in, not in

a = [11,22,33,44]b = 11c = 123print (b in a) =>trueprint (c not in a) => true

Posted in 未分类

发表评论