Fluent_python_part4 object-oriented, 10-seq-hacking, sequence modification, hashing, and slicing

Source: Internet
Author: User
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
  1. Basic sequence protocol--__len__ and GetItem
  2. Correct representation of instances with many elements
  3. Appropriate slice support for generating a new vector instance
  4. Computes the hash value by synthesizing the values of each element
  5. Custom Format Language Extensions
  6. Dynamic fetching of attributes by the __getattr__ method, instead of the read-only attribute used by vector2d--but the sequence type usually does not
  7. In addition, a concept is interspersed: treat the protocol as a formal interface.
  8. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.