[Python-ideas] Add .= as a method return value assignment operator
James Lu
jamtlu at gmail.com
Thu Sep 27 16:48:21 EDT 2018
> items = ["foo", "bar", "quux"]
> items[randrange(3)] .= upper()
>
> Is this equivalent to:
>
> items[randrange(3)] = items[randrange(3)].upper()
>
> ? That would call randrange twice, potentially grabbing one element
> and dropping it into another slot. If it isn't equivalent to that, how
> is it defined?
It would not call randrange twice. Consider existing Python behavior:
def foo():
print("foo")
return 0
l = [7]
l[foo()] += 1
# output: "foo", but only once
print(l) # l == [8]
Sent from my iPhone
> On Sep 27, 2018, at 4:13 PM, Chris Angelico <rosuav at gmail.com> wrote:
>
> That would call randrange twice, potentially grabbing one element
> and dropping it into another slot. If it isn't equivalent to that, how
> is it defined?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180927/0c6666da/attachment.html>
More information about the Python-ideas
mailing list