More on this book
Community
Kindle Notes & Highlights
Started reading
February 23, 2019
The == operator compares the values of objects (the data they hold), while is compares their identities.
+=
= on a tuple creates a new tuple and rebinds the variable l2[2] here.
The problem is that HauntedBus instances that don’t get an initial passenger list end up sharing the same passenger list among themselves.
list. The fix is simple: in __init__, when the passengers parameter is provided, self.passengers should be initialized with a copy of it, as we did correctly in Example 8-8 (“Deep and Shallow Copies of Arbitrary Objects”):
Therefore, we say that a weak reference does not prevent the referent from being garbage collected.
Using eval here shows that the repr of a Vector2d is a faithful representation of its constructor call.2