• 赋值运算符、逻辑运算符补充


    赋值运算符补充
    '''
    增量赋值
    x=10
    x+=1
    '''

    '''
    交叉赋值
    a = 10
    b = 20
    print(a,b)

    temp=b # temp=20
    b=a # b = 10
    a=temp

    python一行代码搞定
    a, b = b, a
    print(a,b)
    '''

    '''
    链式赋值
    a=7
    b=a
    c=b
    d=c

    a = b = c = d = 7
    print(a,b,c,d)
    '''

    '''
    解压赋值: 取开头和结尾的几个值
    salaries=[33,44,55,66,77]
    x=salaries[0]
    y=salaries[1]
    z=salaries[2]
    a=salaries[3]
    b=salaries[4]

    左边变量名的个数与右面包含值的个数相同,多一个不行,少一个也不行
    x,y,z,a,b=salaries
    print(x,y,z,a,b)

    salaries=[33,44,55,66,77,88,99]
    x,y,z,*abc=salaries

    x,y,z会对应列表salaries的前三个值
    然后*会把剩余的值存放一个列表,然后赋值给abc

    print(x,y,z)
    print(abc)

    _当变量名,代表该变量值是无用的
    x,y,z,*_=salaries # 取前三个值
    print(x,y,z)
    print(_)

    salaries=[33,44,55,66,77,88,99]
    *_,m,n=salaries # 取后两个值
    print(_)
    print(m,n)

    salaries=[33,44,55,66,77,88,99]
    x,y,z,*_,m=salaries # 取后两个值
    print(x,y,z)
    print(m)

    d={'a':1,'b':2,'c':3}
    x,y,z=d
    print(x,y,z)
    '''

    逻辑运算符补充
    '''
    一、优先级:not > and > or
    1、not与紧跟其后的那个条件是不可分割的
    2、如果条件语句全部由纯and、或纯or链接,按照从左到右的顺序依次计算即可

    print(True and 10 > 3 and not 4 < 3 and 1 == 1)
    print(False or 10 < 3 or not 4 < 3 or 1 == 1)

    3、对于既有and又有or链接的语句,以and为中心把左右两个条件用
    括号括起来

    res=(10 == 9 and 0 < 3) or ('' == 'egon' and 0> 3) or not True or ('egon' == 'dsb' and 333 > 100) or 10 > 4
    print(res)
    '''

    '''
    2、短路运算=>偷懒原则
    所有的数据类型的值都自带布尔值,所以值可以直接被当成条件使用
    0、None、空三种值对应的布尔值为False,其余全为True

    if 0:
    print('ok')
    else:
    print('=====>')


    if 3 and []:
    print('真')
    else:
    print('假')


    and运算会返回当前计算位置的值
    res=0 and 123
    res=111 and 123
    print(res)


    if 111 and 123:
    print('ok')
    else:
    print('no')

    x=''
    if x:
    print('不为空')
    else:
    print("为空")

    print(1 or 0) # 1
    print(0 and 2 or 1) # 1
    print(0 and 2 or 1 or 4) # 1
    '''
    
    
  • 相关阅读:
    POJ3690:Constellations(二维哈希)
    Codeforces Round #547 (Div. 3) 题解
    Educational Codeforces Round 48 (Rated for Div. 2) CD题解
    Educational Codeforces Round 50 (Rated for Div. 2) C. Classy Numbers
    Codeforces Round #508 (Div. 2) E. Maximum Matching(欧拉路径)
    Codeforces Round #546 (Div. 2) 题解
    Codeforces Round #545 (Div. 2) 题解
    Codeforces Round #544 (Div. 3) 题解
    利用最新Apache解析漏洞(CVE-2017-15715)绕过上传黑名单
    xctf一道反序列化题
  • 原文地址:https://www.cnblogs.com/0B0S/p/12358199.html
Copyright © 2020-2023  润新知