Python built-in function (--object)

Source: Internet
Author: User

English documents:

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

Create a new Object object

Description

1. The object class is the base class for all classes in Python, and if you define a class without specifying which class to inherit, the object class is inherited by default.

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

2. The object class defines some public methods for 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 have a __dict__ defined, so it is not possible to attempt to set property values on object class instance objects.

>>> A = object () >>> a.name = ' Kim ' # Cannot set property Traceback (most recent call last):  File "<pyshell#9>  ; ", line 1, in <module>    a.name = ' Kim ' attributeerror: ' Object ' object has no attribute ' name ' #定义一个类A >>> Class A:    pass>>> a = A () >>> >>> a.name = ' Kim ' # can set properties

Python built-in function (--object)

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.