> As I see it, you are mixing very different things. Augmented operators in Python work on objects, generally trying to mutate them in-place. So usually after these operations you have the same object (with the same type, with the same name and etc.) as before these operations. Of course there are exceptions, for example all immutable types or some promotions between numbers.
Yep. >>> a = (5, 2) >>> a += (3, ) >>> a (5, 2, 3) > In your examples some cases imply that you are working on names, others that you are working on objects. And as for me this ambiguity is not solvable. example please? Show an ambiguous case. To me, it's always working on names. On Thu, Sep 27, 2018 at 5:32 PM Kirill Balunov <kirillbalu...@gmail.com> wrote: > As I see it, you are mixing very different things. Augmented operators in > Python work on objects, generally trying to mutate them in-place. So > usually after these operations you have the same object (with the same > type, with the same name and etc.) as before these operations. Of course > there are exceptions, for example all immutable types or some promotions > between numbers. > > In your examples some cases imply that you are working on names, others > that you are working on objects. And as for me this ambiguity is not > solvable. > > With kind regards, > -gdg > > ср, 26 сент. 2018 г. в 14:14, Jasper Rebane <rebane2...@gmail.com>: > >> 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/ >> > _______________________________________________ > Python-ideas mailing list > Python-ideas@python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ >
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/