About 50 results
Open links in new tab
  1. Python conditional assignment operator - Stack Overflow

    Python conditional assignment operator Asked 14 years, 8 months ago Modified 4 years, 2 months ago Viewed 204k times

  2. Best way to do conditional assignment in python

    Jul 15, 2011 · Best way to do conditional assignment in python Ask Question Asked 14 years, 7 months ago Modified 4 years, 1 month ago

  3. python - One line if-condition-assignment - Stack Overflow

    Oct 24, 2011 · One should not use this approach if looping through large data sets since it introduces an unnecessary assignment in case we end up in the else-statement.

  4. Conditional/ternary operator for expressions in Python

    Many languages have a conditional (AKA ternary) operator. This allows you to make terse choices between two values based on a condition, which makes expressions, including assignments, …

  5. python - Can we have assignment in a condition? - Stack Overflow

    PEP 572 seeks to add assignment expressions (or "inline assignments") to the language, but it has seen a prolonged discussion over multiple huge threads on the python-dev mailing list—even after multiple …

  6. python - How to assign a variable in an IF condition, and then return ...

    Apr 27, 2019 · 189 Starting Python 3.8, and the introduction of assignment expressions (PEP 572) (:= operator), it's now possible to capture the condition value (isBig(y)) as a variable (x) in order to re …

  7. python - Is it possible to make multiple assignments using a ...

    Jun 1, 2017 · The syntax you requested is not possible. The conditional expression syntax is true-expression if condition else false-expression.

  8. Does Python have a ternary conditional operator?

    Dec 27, 2008 · 214 From the documentation: Conditional expressions (sometimes called a “ternary operator”) have the lowest priority of all Python operations. The expression x if C else y first …

  9. One line if assignment in python - Stack Overflow

    Jul 20, 2015 · following this topic One line if-condition-assignment Is there a way to shorten the suggested statement there: num1 = (20 if intvalue else 10) in case that the assigned value is the …

  10. python - What are assignment expressions (using the "walrus" or ...

    117 Since Python 3.8, code can use the so-called "walrus" operator (:=), documented in PEP 572, for assignment expressions. This seems like a really substantial new feature, since it allows this form of …