(no title)
jp57 | 11 days ago
a = b = random.random()
I would not expect a and b to get different values. It would be very strange if using `[]` had different behavior than a function call in the same place. Am I out of step here?jp57 | 11 days ago
a = b = random.random()
I would not expect a and b to get different values. It would be very strange if using `[]` had different behavior than a function call in the same place. Am I out of step here?
maxnoe|11 days ago
The initial line is the same, but:
Only because floats are immutable and thus an implicit copy is made and lists are mutable so the same mutable instance is pointed to by both names.This talk still applies despite its age: https://youtu.be/_AEJHKGk9ns?si=q5HjMOM9QS3_bFzH
jp57|10 days ago
jibal|11 days ago
A somewhat trickier example of the same issue is using [] as a default parameter value ... though there are warnings about the problem with that (it's the same list on every call) throughout the documentation.