Python's program structure [2]-Class/class-Class special properties

Source: Internet
Author: User

Special properties of the class /Special property of Class

In Python, classes are defined by class, and classes can be instantiated into instances and invoked using an instance.

The class also contains some common special properties.

Special class Properties

Meaning

__name__

The name of the class (string)

__doc__

The document string for the class

__bases__

A tuple that consists of all the parent classes of the

__dict__

A dictionary of the properties of a class

__module__

module to which the class belongs

__class__

Type of class object

1 classFoo ():2     """3 This is the text of the can be called by __doc__4     """5     def __init__(self):6Self.foo =None7 8     defFoo_method (self):9Self.foom =TrueTen  One Print('>>>'Foo.__name__) A Print('>>>'Foo.__doc__) - Print('>>>'Foo.__bases__) - Print('>>>'Foo.__dict__) the Print('>>>'Foo.__module__) - Print('>>>'Foo.__class__)

The above code defines a Foo class and invokes the basic special properties of the class in turn, resulting in the following results.

>>>Foo>>> This isThe text that can is called by__doc__>>> (<class 'Object'>,)>>> {'__dict__': <attribute'__dict__'Of'Foo'Objects>,'__doc__':'\ n This is the text, can be called by __doc__\n','__weakref__': <attribute'__weakref__'Of'Foo'Objects>,'__init__': <function Foo.__init__At 0x0301f930>'__module__':'__main__','Foo_method': <function Foo.foo_method at 0x0305c348>}>>>__main__>>> <class 'type'>

Python's program structure [2]-Class/class-Class special properties

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.