[Python-ideas] Keyword same in right hand side of assignments
Steven D'Aprano
steve at pearwood.info
Mon Mar 16 19:18:35 CET 2009
On Tue, 17 Mar 2009 03:37:59 am Heinrich W Puschmann wrote:
> Python-Ideas: Keyword same in right hand side of assignments
> ---------------------------------------------------------------------
>----------------------
>
> It is proposed to introduce a Keyword "same",
> to be used in the right hand side of assignments, as follows:
>
> "xx = same + 5" or "xx = 5 + same" synonymous with "xx += 5"
> "value = 2*same + 5" synonymous with "value =*2; value +=5"
> "switch = 1 - same" synonymous with "switch *-1; switch +=1"
> "lst = same + [5,6]" synonymous with "lst += [5,6]"
> "lst = [5,6] + same" synonymous with "lst = [5,6] + lst"
> "lst[2] = 1/same" synonymous with "lst[2] **=-1"
>
> and so on.
What's the point? Why not just write the following?
xx = xx + 5
value = 2*value + 5
switch = 1 - switch
lst = lst + [5,6]
lst = [5,6] + lst
lst[2] = 1/lst[2]
What value do we gain by creating a new keyword that obscures what the
assignment does?
--
Steven D'Aprano
More information about the Python-ideas
mailing list