Hi,

When using Python, I find myself often using assignment operators, like 'a
+= 1' instead of 'a = a + 1', which saves me a lot of time and hassle

Unfortunately, this doesn't apply to methods, thus we have to write code
like this:
text = "foo"
text = text.replace("foo","bar")
# "bar"

I propose that we should add '.=' as a method return value assignment
operator so we could write the code like this instead:
text = "foo"
text .= replace("foo","bar")
# "bar"
This looks cleaner, saves time and makes debugging easier

Here are a few more examples:
text = " foo "
text .= strip()
# "foo"

text = "foo bar"
text .= split(" ")
# ['foo', 'bar']

text = b'foo'
text .= decode("UTF-8")
# "foo"

foo =  {1,2,3}
bar = {2,3,4}
foo .= difference(bar)
# {1}


Rebane
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to