zoukankan      html  css  js  c++  java
  • python集合可以进行相减

    python集合可以进行相减

    student = {'tom','jim','mary','tom','jack','rose'}
    print(student)
    print('rose' in student)
    a = set('abcd')
    b = set('cde')
    print(a,b,a-b,a|b,a&b,a^b)#{'b', 'a', 'd', 'c'} {'c', 'e', 'd'} {'b', 'a'} {'c', 'e', 'b', 'a', 'd'} {'c', 'd'} {'b', 'e', 'a'}
    c,d = {},set()
    print(type(c),type(d)) #<class 'dict'> <class 'set'>

    注意{}是字典,不是集合;

     a^b = (a|b)-(a&b);注意必须加括号;

    a = set('abcd')
    b = set('cde')
    print(a^b) #{'b', 'e', 'a'}
    print(a|b) #{'d', 'e', 'b', 'a', 'c'}
    print(a&b) #{'d', 'c'}
    print((a|b)-(a&b)) #{'a', 'e', 'b'}
    #注意 运算符的优先级会导致问题的,必须加括号
    print(a|b-a&b) #{'d', 'c', 'a', 'e', 'b'}
  • 相关阅读:
    hinge loss
    KL散度
    pygame 学习
    pytorch 反向传播
    在线画数学函数图
    recover deleted files
    98个关键点的人脸
    Pytorch详解BCELoss和BCEWithLogitsLoss
    one hot vector
    Effective C++
  • 原文地址:https://www.cnblogs.com/stono/p/8510676.html
Copyright © 2011-2022 走看看