Top "Ternary-operator" questions

The conditional operator is a ternary operator that is part of the syntax for a basic conditional expression in several programming languages.

Does Python have a ternary conditional operator?

If Python does not have a ternary conditional operator, is it possible to simulate one using other language constructs?

python operators ternary-operator conditional-operator
Putting a simple if-then-else statement on one line

I'm just getting into Python and I really like the terseness of the syntax. However, is there an easier way …

python if-statement syntax ternary-operator
Short form for Java if statement

I know there is a way for writing a Java if statement in short form. if (city.getName() != null) { name = …

java if-statement ternary-operator
Omitting the second expression when using the if-else shorthand

Can I write the if else shorthand without the else? var x=1; x==2 ? dosomething() : doNothingButContinueCode(); I've noticed putting null for …

javascript ternary-operator conditional-operator shorthand
How to write an inline IF statement in JavaScript?

How can I use an inline if statement in JavaScript? Is there an inline else statement too? Something like this: …

javascript if-statement ternary-operator conditional-operator
How do I use the conditional operator (? :) in Ruby?

How is the conditional operator (? :) used in Ruby? For example, is this correct? <% question = question.size > 20 ? question.question.…

ruby ternary-operator conditional-operator
What is a Question Mark "?" and Colon ":" Operator Used for?

Two questions about using a question mark "?" and colon ":" operator within the parentheses of a print function: What do they …

java operators ternary-operator conditional-operator
How do I use the ternary operator ( ? : ) in PHP as a shorthand for "if / else"?

Based on the examples from this page, I have the working and non-working code samples below. Working code using if …

php ternary-operator conditional-operator
One-line list comprehension: if-else variants

It's more about python list comprehension syntax. I've got a list comprehension that produces list of odd numbers of a …

python list-comprehension ternary-operator conditional-operator
inline conditionals in angular.js

I was wondering if there is a way in angular to conditionally display content other than using ng-show etc. For …

angularjs if-statement ternary-operator