new feature in Python
Christman, Roger Graydon
dvl at psu.edu
Wed Sep 30 13:05:41 EDT 2020
On 30/09/2020, yonatan <5377074j at gmail.com> proposed:
> instead of
> con = "some text here"
> con = con.replace("here", "there")
> we could do
> con = "some text here"
> con .= replace("here", "there")
That would require a major rewrite of the grammer
of the Python language, which would probably be a bad thing.
The operands to all of those assignment operators are
complete objects in their own rights. This 'replace'
is not an independent object, but a member of the
string object. Without that "con." in front of it,
you would likely get the error about
"'replace' not defined"
For the grammar to be clean and orthogonal,
it would not be at all good to have a context-sensitivity
introduced to allow orphaned method names to be
permitted, just because there was this ".=" token
somewhere earlier in the program statement.
Besides, I could foresee a lot of programming
errors when people would start to generalize this
operation to do things like:
list .= append(item)
list .= sort()
which would most certainly be incorrect.
Roger Christman
Pennsylvania State University
More information about the Python-list
mailing list