About 37,300 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 this form of …

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

    156 This symbol := is an assignment operator in Python (mostly called as the Walrus Operator). In a nutshell, the walrus operator compresses our code to make it a little shorter. Here's a very simple …

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

    Nov 26, 2020 · day,hour,mins,sec := i.split(':') is invalid. Walrus operator is recommended to be used mostly in logic comparison, especially when you need to reuse a variable in comparison. Therefore, I …

  4. python - Why do I get an infinite while loop when changing initial ...

    Why do I get an infinite while loop when changing initial constant assignment to "walrus operator"? Asked 4 years, 11 months ago Modified 11 months ago Viewed 16k times

  5. 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 get_prefix(name): ...

  6. python - Multiple conditions for "walrus operator" assignment - Stack ...

    Multiple conditions for "walrus operator" assignment Asked 5 years, 7 months ago Modified 5 years, 7 months ago Viewed 5k times

  7. Why is Python walrus operator (:=) needed instead of just using the ...

    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 as expression,...

  8. Use walrus operator in Python 3.7 - Stack Overflow

    The walrus operator was introduced in Python 3.8, so if you are using a version prior to 3.8 then it does not contain an implementation of that operator, so you cannot use it. There was no need to use …

  9. syntax error - Why can't Python's walrus operator be used to set ...

    Sep 24, 2020 · I just learned that the new walrus operator (:=) can't be used to set instance attributes, it's supposedly invalid syntax (raises a SyntaxError). Why is this? (And can you provide a link to official

  10. python - What is the correct syntax for Walrus operator with ternary ...

    Aug 6, 2020 · I'm failing to wrap my mind around the syntax. Having tried various combinations, every time the interpreter throws SyntaxError: invalid syntax. My python version is 3.8.3. My question is …