From cosarara@cosarara@tilde.club to tilde.python on Wed Dec 22 09:56:19 2021
Run the following code:
a = a[0] = [0]
print(a)
Do you think it will error out on the first line? Can you explain how it works? Think about it, then read below for the answer:
Chained assignment in python takes the rightmost element and assigns
left to right, such that the statement boils down to:
tmp = [0]
a = tmp
a[0] = tmp
Thus creating a as a list of one element, that element being itself.
This is probably the most confusing and satisfyingly evil python trick I
know. Do you know other interesting tricks?
--- Synchronet 3.19a-Linux NewsLink 1.113
Who's Online
Recent Visitors
Dextile
Fri Dec 27 13:28:22 2024
from
Calgary, Ab
via
Telnet
Deepend
Fri Dec 27 13:13:36 2024
from
Calgary, Ab
via
HTTPS
Guest
Fri Dec 27 08:11:25 2024
from
Melbourne, Victoria
via
Telnet
Dextile
Fri Dec 27 06:29:55 2024
from
Calgary, Ab
via
Telnet