About 46,600 results
Open links in new tab
  1. 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.

  2. python - How to assign a variable in an IF condition, and then …

    Apr 27, 2019 · The one liner doesn't work because, in Python, assignment (fruit = isBig(y)) is a statement, not an expression. In C, C++, Perl, and countless other languages it is an …

  3. What does colon equal (:=) in Python mean? - Stack Overflow

    Mar 21, 2023 · What does the := operand mean, more specifically for Python? Can someone explain how to read this snippet of code? node := root, cost = 0 frontier := priority queue …

  4. 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 …

  5. Assign variable in while loop condition in Python?

    Starting Python 3.8, and the introduction of assignment expressions (PEP 572) (:= operator), it's now possible to capture the condition value (data.readline()) of the while loop as a variable …

  6. Python Multiple Assignment Statements In One Line

    Aug 22, 2015 · An assignment statement evaluates the expression list (remember that this can be a single expression or a comma-separated list, the latter yielding a tuple) and assigns the …

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

    Apr 8, 2010 · 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 …

  8. python - How can I do assignments in a list comprehension

    Apr 24, 2012 · The Python language has distinct concepts for expressions and statements. Assignment is a statement even if the syntax sometimes tricks you into thinking it's an …

  9. coding style - Assignment with "or" in python - Stack Overflow

    Jan 6, 2012 · Is it considered bad style to assign values to variables like this? x = "foobar" or None y = some_variable or None In the above example, x gets the value 'foobar'.

  10. Best way to do conditional assignment in python

    Jul 15, 2011 · Best way to do conditional assignment in python Asked 14 years, 2 months ago Modified 3 years, 8 months ago Viewed 25k times