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
System Info
Sysop:
deepend
Location:
Calgary, Alberta
Users:
293
Nodes:
10 (0
/
10)
Uptime:
31:12:17
Calls:
2,481
Files:
5,520
D/L today:
30 files
(10,053K bytes)
Messages:
454,534
Synchronet Oneliners
Vintagegeek@rdbbs Sat Dec 20 14:04:54 2025 Buehler
Ben Cartwright@rdbbs Mon Dec 29 08:15:35 2025 Hi!
Vintagegeek@rdbbs Fri Jan 2 13:31:40 2026 H A P P Y NEW YEAR
Guest@rdbbs Sat Jan 10 10:41:07 2026 Greetings Programs
Vintagegeek@rdbbs Tue Jan 13 13:09:57 2026 Look At That Moon
Deepend@rdbbs Mon Jan 26 00:12:58 2026 I'd have to go outside.. lol