Python built-in functions (45) -- object, pythonobject

Source: Internet
Author: User

Python built-in functions (45) -- object, pythonobject

English document:

Class object
Return a new featureless object. object is a base for all classes. It has the methods that are common to all instances of Python classes. This function does not accept any arguments.
Note: object does not have a _ dict __, so you can't assign arbitrary attributes to an instance of the object class.

 

Note:

1. The object class is the base class of all classes in Python. If no class is specified to be inherited when defining a class, the object class is inherited by default.

>>> class A:    pass>>> issubclass(A,object)True

2. The object class defines some common methods of all classes.

>>> dir(object)['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']

3. The object class does not define _ dict __, so you cannot set the attribute value for the object class instance object.

>>> A = object () >>>. name = 'Kim '# attributes Traceback (most recent call last) cannot be set: File "<pyshell #9>", line 1, in <module>. name = 'Kim 'AttributeError: 'object' object has no attribute 'name' # define A class A >>> class: pass >>> a = A () >>>>>. name = 'Kim '# attributes can be set

 

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.