So be sure to ponder your reasons when choosing the ternary operator.
所以在挑选三元运算符时,请务必权衡一下利弊。
This new operator is, in fact, a shortcut notation for the ternary operator.
这个新操作符实际上是一个三目操作符的便捷记法。
For Java developers, this is exactly the way the ternary operator — the? : expression — works.
表达式——的工作方式。
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变量的第二次出现被简单的忽略了,三目操作符不再是三目的了,缩短为这种更简明的形式。
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 expression can be as simple as a variable (as shown in Listing 2) or a method call (like getList()), or a complex expression that involves boolean logic or a ternary operator.
表达式可以简单到就是一个变量(如清单2 所示)或者是一个方法调用(例如getList()),亦或是包含布尔逻辑或三目运算符的复杂表达式。
Avoid using the ternary conditional operator.
避免使用3元条件运算符。
Avoid using the ternary conditional operator.
避免使用3元条件运算符。
应用推荐