Tag:Go ternary operator

  • Why there is no ternary operator in golang

    Time:2021-4-30

    Ternary operators are widely used in other languages python: val = trueValue if expr else falseValue javascript: const val = expr ? trueValue : falseValue c、c++: const char *val = expr ? “trueValue” : “falseValue”; However, the widely supported ternary operator does not exist in golang! If we write something like this: val := expr […]