Programmatic distinction between ternary then function call versus function call dependent on condition
<p>Recently I have been conflicted regarding the following question. It may just be a stylistic choice, but I was wondering if there is a programmatic difference between the following... (in python, but applicable for most languages)</p>

<p>Case #1:</p>

<pre><code>arg = A if condition else B
result = func(arg)
</code></pre>

<p>Case #2:</p>

<pre><code>if condition:
    result = func(A)
else:
    result = func(B)
</code></pre>

<p>Is there an industry standard for choosing between these two? Is there a programmatic difference?</p>

<p>My opinion is in Case #1 you'd better be sure that you're checking for some kind of binary condition, e.g. an integer is either odd or even. In thoses cases I'd prefer Case #1 for the sake of simplicity.</p>

<p>If the expression in the condition is not binary, such as checking the remainder of an integer module n, with n > 2, you make need to use a nested ternary expression, and the code gets hard to read quickly. In theses cases, Case #2 would be better.</p>

python function ternary-operator