
|:=| 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%20pr...>" 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)

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

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