> 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 <ros...@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?
_______________________________________________
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