Part IV 10th, modification, hashing, and slicing of sequences
Chinese e-book P423
In this chapter, the 1th and 9th chapters are based on the Vector2d class defined in chapter 9th, which defines vector classes that represent many vectors. The behavior of this class is the same as the standard immutable flat sequence in Python. The elements in the vector instance are floating-point numbers, and the vector classes in this chapter support the following features
- Basic sequence protocol--__len__ and GetItem
- Correct representation of instances with many elements
- Appropriate slice support for generating a new vector instance
- Computes the hash value by synthesizing the values of each element
- Custom Format Language Extensions
- Dynamic fetching of attributes by the __getattr__ method, instead of the read-only attribute used by vector2d--but the sequence type usually does not
- In addition, a concept is interspersed: treat the protocol as a formal interface.
- protocol with Duck type P430
Leave pits, too complex, to look directly
Fluent_python_part4 object-oriented, 10-seq-hacking, sequence modification, hashing, and slicing