Add .= as a method return value assignment operator
27 Sep
2018
27 Sep
'18
1:48 p.m.
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
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?
2037
Age (days ago)
2037
Last active (days ago)
0 comments
1 participants
participants (1)
-
James Lu