Re:PEP 572: Python assignment expressions has been accepted
by codetrotter on Tuesday July 03, 2018 @06:00PM
(#17453913)
> I don't know what you would lose by having if as an expression
Well, if you turn if into an expression the way that you indicated then now you will also need the equivalent of the “begin” expression in order to be able to have multiple statements and/or expressions in either branch.
So then you are breaking backwards compatibility. Which makes it a non-starter from the get go.
And like I said there is also the fact that functions need the return keyword in Python if you want to return a value.
Re:PEP 572: Python assignment expressions has been accepted
by bjoli on Thursday July 05, 2018 @03:22AM
(#17461450)
You could have the same looks as the regular if, but have it implicitly return a value. I was just too sleep deprived to be able to type out correct syntax on my phone.
Ruby returns the last thing in a method, which I feel is pretty sane.
I don't know what you would lose by having if as an expression. It is easy to notice when it is used in expression context, and there is no extra computation that needs to be done.
It was sort of addressed with the trenary operator, but that quickly becomes ugly.