![](https://secure.gravatar.com/avatar/f5ccc6c2d89c0aa40769d36e442116e4.jpg?s=120&d=mm&r=g)
|:=| Assignment expression In the web documentation at the end of the table in 6.17. "Operator precedence <https://docs.python.org/3/reference/expressions.html?highlight=operator%20precedence#operator-precedence>" is the Assignment expression. What is that colon doing there? I can't type "x := 23" to Python, it gives me "SyntaxError: invalid syntax" as you would expect. None of the other operators have a colon introducer, so why with '='? Thanks, John Hallyburton (Python fan for many a yarn)
![](https://secure.gravatar.com/avatar/25e4871f654fadce362582f3ee4769c6.jpg?s=120&d=mm&r=g)
On Tue, Apr 4, 2023 at 9:23 PM John Hallyburton <johnhideaway@tds.net> wrote:
In the web documentation at the end of the table in 6.17. "Operator precedence" is the Assignment expression. What is that colon doing there? I can't type "x := 23" to Python, it gives me "SyntaxError: invalid syntax" as you would expect. None of the other operators have a colon introducer, so why with '='?
Hi John, `:=` is a new operator as of Python 3.8, but `x := 23` is not allowed as a standalone statement because it's not useful: the "return" value has nowhere to go. Try `x = (y := 23)`, or something with a bit more purpose like: i = 5 while (i := i - 1): print(i) -- Zach
participants (2)
-
John Hallyburton
-
Zachary Ware