Python-related knowledge

Source: Internet
Author: User

Declaring a function in Python is similar to declaring a class

def functionname (arge):    "function document String"    #函数体    #声明类class class name:    "Document String for class"    class body

Classic class:

Class Chinese:    ' This is a Chinese class '    pass# uses class Chinese to instantiate an object D1D1 = Chinese () Print D1

New class:

#新式类class Chinese2 (object):    Pass

#属性: A class is used to describe a class of things, the object of which refers to an individual in this kind of thing, is the thing must have the attribute, the attribute divides into
#1, the Data property is the variable
#2, function properties, which are functions, are often called methods in object-oriented
#注意: Classes and objects use points to access their properties

Data properties

Class China:    goverment = "123" Print china.goverment

function properties

Class China:    goverment = "123"    def Sui_di (): #函数属性        print ("commonality")    def Cha_dui (self):        print "front" print China.govermentChina.sui_di ()

The invocation of the property

__DICT__: Properties of the Class (contains a dictionary, consisting of the data properties of the Class)

__DOC__: Document string for Class

__NAME__: Class name

__MODULE__: The module where the class definition resides (the full name of the class is ' __main__.classname ', if the class is in an import module mymod, then classname.__module__ equals Mymod)

__BASES__: All parent classes of a class make up elements that contain a tuple of all the parent classes

#类的其他属性
Print China. __name__
Print China. __doc__
Print China. __bases__
Print China. __module__

Python-related knowledge

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.