Can we initialize Python objects with statement like this:
a = b = c = None
It seems to me when I did a = b = c = list()
, it will cause a circular reference count issue.
CARVIEW |
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about CollectivesTeams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about TeamsCan we initialize Python objects with statement like this:
a = b = c = None
It seems to me when I did a = b = c = list()
, it will cause a circular reference count issue.
There are no cycles in your code and even if there were, Python's garbage collector can handle a circular reference fine, so you don't ever need to worry about that.
However your code has another (possible) problem: All three variables will point to the same list. This means that changing, for example, a, will also change b and c (where by "changing" I mean calling a mutating operation like for example append
. Reassigning a variable will not affect the other variables).
Yes, you can do that. There is no circular reference in your code and even if there were, it wouldn't cause any problems as Python has a garbage collector that correctly handles cycles.
No. That's equivalent to:
c = list() b = c a = b
There is no problem. Why did you think there would be an issue?