The difference between type and object in Python

Source: Internet
Author: User

The difference between type and object in Python after looking at the Python API, it finally dawned on you. Now summarized as follows:

First look at the description of object:

There are few or even a few words about object in Python:

    1. Class object
    2. The most base type

From the introduction, this is also Python's efforts to unify the type. So the object here is similar to the Java object class, and it can be inferred that this object is probably a "null class" that defines a type.

Then look at the description of type:

  1. class type (object)
  2. Type (object), the object ' s type
  3. Type (name, bases, Dict), a new type
  4. Methods defined here:
  5. __call__ (...)
  6. X.__call__ (...) <==> x (...)
  7. __cmp__ (...)
  8. x.__cmp__ (y) <==> cmp (x, y)
  9. __delattr__ (...)
  10. x.__delattr__ (' name ') <==> del x.name
  11. __getattribute__ (...)
  12. x.__getattribute__ (' name ') <==> x.name
  13. __hash__ (...)
  14. x.__hash__ () <==> hash (x)
  15. __repr__ (...)
  16. x.__repr__ () <==> repr (x)
  17. __setattr__ (...)
  18. x.__setattr__ (' name ', value) <==> X.name = value
  19. __subclasses__ (...)
  20. __subclasses__ (), List of immediate subclasses
  21. MRO (...)
  22. MRO () List
  23. Return a type ' s method resolution order

Since you should understand the difference between type and object. If you usually define the class, you want to be lazy as much as possible, you can inherit directly from the type, otherwise it is recommended to inherit object

Also put on the actual operation of the difference it:







The difference between type and object in Python

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.