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