Knowledge such as python

Declaring a function in Python is very similar to declaring a class

def functionName(arge):
    "function docstring"
    #function body
    
#declare class
class class name:
    "docstring for class"
    class body

 Classic class:

class Chinese:
    'This is a Chinese class'
    pass

#Instantiate an object d1 with class Chinese
d1 = Chinese()
print d1

 New class:

#new class
class Chinese2(object):
    pass

 #Attribute: A class is used to describe a class of things. The object of the class refers to an individual in this class of things. If it is a thing, it must have attributes. Attributes are divided into
#1, data attributes, which are variables
#2, function attributes , is a function, usually called a method in object-oriented #Note
: Both classes and objects use dots to access their own properties

 

data attribute

 

class China:
    goverment = "123"

print China.goverment

 

 function property

class China:
    goverment = "123"
    def sui_di(): #function attributes
        print ("common")
    def cha_dui(self):
        print "front"

print China.goverment
China.sui_di ()

 property call

print dir(China)
print China.__dict__ #View the attribute dictionary of the class
print China.__dict__["goverment"]#Attribute dictionary call attribute
China.__dict__["sui_di"]()

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325156061&siteId=291194637