代码之家  ›  专栏  ›  技术社区  ›  tim687

Python的C++等式是(var=value,var)吗

  •  -3
  • tim687  · 技术社区  · 2 年前

    uint8_t one = 0;
    
    if ((one = randomUint8t(), one) == 255){
     printf("One has the max uint8_t value");
    }
    

    因此,将随机uint8函数的值赋给 one 用于表达式计算。

    1 回复  |  直到 2 年前
        1
  •  1
  •   TheEagle    2 年前

    这是可能的,因为Python3.8具有 assignment expressions aka the "walrus" operator := .示例:

    import random
    
    if (one := random.randint(0, 255)) == 255:
        print("one == 255")