19. Python and applied MLPython for C++ programmers
Python for C++ programmers
Python looks like pseudocode, but its object model is different from C++ in ways that cause real bugs. Every value is an object on the heap, and a variable is just a name bound to one, so assignment never copies: two names can share one list, and changing it through either is visible through both. Default arguments are created once, when the function is defined, so a default list is shared by every call. Integers floor-divide toward negative infinity, round() rounds ties to even, and floats can't hold most decimal amounts exactly, which matters for money. This lesson makes the model visible, then drills the bugs it causes.
In this lesson: Step through names pointing at objects (aliasing, rebinding, default arguments), predict the output of eight snippets, then drill the pitfalls in the Python track.