设为首页收藏本站
查看: 87|回复: 0

[PHP] python基础-运算符

[复制链接]

论坛元老

Rank: 6Rank: 6

积分
34274
主题
17031
UID
1347
M币
67
贡献
17176

  • 发表于 2017-5-14 02:44:00 | 显示全部楼层 |阅读模式
    运算符
    1、算数运算: +,-,*,/,%,**,//
    print (3+2) => 5print (3-2) => 1print (2*4) => 8print (9/3) => 3print (2**2) => 4print (100%51) => 49print (9//2) => 4
    2、比较运算: ==,!=,,>,=,
    print (3==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 = 11
    c = 123
    print (b in a) =>True
    print (c not in a) => True
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    在我站开通SVIP可同时获得17个站点VIP资源 立即登录 立即注册
    快速回复 返回顶部 返回列表