3
Day 3 reading notes
j edited this page 2023-03-31 22:29:18 +02:00

3.1

Note that the type() and id() builtin methods work both on themselves, and each other.

Experiment: what is the class of the type() method? If you use dir() on the type class, there's an interesting method at the end of the list of the class contents, what does it do?

The reason why the language reference is specific about saying that containers contain references to objects is that it's trying to tell programmers that Python does not copy objects to make data structures. This means that modifying objects inside containers will modify the one, original version of the object. Keep in mind that third-party libraries may not always make this guarantee, especially when it comes to big data, for performance reasons.

Keep in mind that Python itself may sometimes change the identity of an object, such as when promoting an integer to a bignum because it got too large, but that doesn't affect the other guarantees expressed here.

3.2

The phrase "access to the implementation" is a warning sign saying "don't do this." Python, the language, is an abstract concept which makes certain guarantees that if you type Python code and run it, certain things will happen. There are many different implementations of Python (see chapter 1). Poking around in how the implementation works breaks the guarantee that Python code will run the same on CPython, Jython, etc, and is generally only done for performance or troubleshooting reasons.

In most cases, Python analysis work doesn't involve data literals as input, that usually comes from a database or API. It does use data literals as output, which is why focusing so much on formatting issues is important: output must be clear and unambiguous.

This section is about the abstract concept of that data, which is how it exists in computer memory as bytes.

Thought experiment: if you have a sequence where you set only entries 1 and 100 to a value, what do you think should happen if someone accesses entry 50?

Note that ord and chr are inverses of each other.

Attributes have a more precise definition, but for now just understand that an attribute is a property of a Python object which contains either data or code. Attributes are key to making your software easily usable by others, and for you to inspect other code modules that you may be troubleshooting or working with.

Don't worry about fully understanding the details of the class definitions, but you should take apart the paragraph that starts with "When a class attribute reference..." with a fine-tooth comb so you understand exactly what each of the terms mean, especially the difference between a class method object and a static method object.