Fluent_python_part4 object-oriented, 09-pythonic-obj,python-style objects

Source: Internet
Author: User

Part IV the 9th chapter, the Python style object

This chapter is followed by the 1th chapter, which illustrates the common method of special implementation.

This chapter covers the topic:
  1. Supports built-in functions for generating other representations of objects (such as repr (), bytes (), and so on)
  2. Implementing alternative construction methods using a class method
  3. Extend the format of the built-in formats () and Str.format () to micro-language
  4. Implement read-only properties
  5. Turns an object into a hash so that it is used in the collection and as a Dict key
  6. Save memory with __slots__
  7. How and when to use the @classmethod and @staticmethod adorners
  8. Usage, conventions, and limitations of private and protected properties for Python
    A simple two-dimensional Euclidean vector type will be developed, covering all of the above topics in this process.
    Mimics the behavior of the Python standard object, allowing the vector to behave in Python style.
1. Object representation

Object-oriented languages have at least one standard form of getting the string representation of an object. Python is available in two ways.
1.1 repr (): Returns the string representation of an object in a way that is easy for developers to understand .
1.2 str (): Returns the string representation of an object in a way that is easy for the user to understand .
1.3 Implements __REPR__ and __str__ special methods to provide support for repr () and STR ().
1.4 repr,str, and __format__ all return Unicode strings (str type). Only the __bytes__ method should return a sequence of bytes (bytes type).

Leave the pit, it's too complicated.

Chinese e-book P387

Fluent_python_part4 object-oriented, 09-pythonic-obj,python-style objects

Related Article

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.