ternary operator

[ˈtɚnəri ˈɑpəˌretɚ][ˈtə:nəri ˈɔpəreitə]

三元算子

  • 3.1.9 Ternary if-else operator

    3.1.9 if-else 运算符

  • PHP has the ternary operator ( foo ? bar : baz ) and an enormous ( and unwieldy ) list of function names with all kinds of naming conventions ; you 'll find Python a lot cleaner .

    PHP使用 操作符(foo?bar:baz)和冗长的函数名列表,而命名约定更是无所不有;相反,您会发现Python要简洁多了。

  • This new operator is in fact a shortcut notation for the ternary operator .

    这个新操作符实际上是一个 操作符的便捷记法。

  • Of course you could use an ordinary if-else statement ( described later ) but the ternary operator is much terser .

    当然,也可以换用普通的if-else语句(在后面介绍),但 运算符更加简洁。

  • Avoid using the ternary conditional operator .

    避免使用 3 条件 运算符

  • The second occurrence of the name variable is simply omitted and the ternary operator is no more ternary and is shortened to this more concise form .

    name变量的第二次出现被简单的忽略了, 操作符不再是三目的了,缩短为这种更简明的形式。

  • How many times are you using the ternary operator to change the value of a variable if its content is null to assign it some default value ?

    你是否经常使用 操作符来改变一个变量的值?