About 1,070,000 results
Open links in new tab
  1. 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 …

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

  3. Walrus operator in list comprehensions (python) - Stack Overflow

    Nov 27, 2023 · Walrus operator is recommended to be used mostly in logic comparison, especially when you need to reuse a variable in comparison. Therefore, I would argue that for …

  4. Using a walrus operator in if statement does not work

    May 12, 2021 · I have a simple function that should output a prefix based on a pattern or None if it does not match. Trying to do a walrus it does not seem to work. Any idea? import re def …

  5. Why is Python walrus operator (:=) needed instead of just using …

    Sep 8, 2022 · I just learned there is a walrus operator in Python 3.8 if a := 2 + 3: print(a) # 5 I wonder why they created a new operator instead of allowing the existing assignment operator …

  6. python - What is the correct syntax for Walrus operator with …

    Aug 6, 2020 · What is the correct syntax for Walrus operator with ternary operator? Asked 5 years, 3 months ago Modified 2 years, 10 months ago Viewed 6k times

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

    Oct 24, 2011 · 52 For the future time traveler from Google, here is a new way (available from Python 3.8 onward): b = 1 if a := b: # this section is only reached if b is not 0 or false. # Also, a …

  8. python - Cannot use assignment expressions with subscript

    Mar 28, 2020 · if session['dp'] := current_user.avatar : ^ SyntaxError: cannot use assignment expressions with subscript Why Python forbids this use of walrus operator?

  9. How to perform assignment destructuring using the walrus …

    Dec 7, 2019 · How to perform assignment destructuring using the walrus operator in Python Asked 5 years, 10 months ago Modified 6 months ago Viewed 7k times

  10. python - Walrus Operator in match statement results in invalid …

    Aug 28, 2023 · Walrus Operator in match statement results in invalid syntax Asked 2 years ago Modified 2 years ago Viewed 1k times