This article mainly for everyone in-depth analysis of the Python static method and dynamic methods of the relevant information, with a certain reference value, interested in small partners can refer to
#-*-Coding:utf-8-*-"" "Created on Sun Nov 23:19:03 @author: Toby" "" #知识点: Static method and dynamic method # static method belongs to class # dynamic method belongs to object class Provin CE: memo = ' One of China\ ' s provinces ' #静态字段 def __init__ (self,name,capital,leadership): Self . Name = name #动态字段 self . Capital = Capital #动态字段 self . Leadership = Leadership #动态字段 def Sports (self): #定义一个动态方法, the class cannot access the dynamic method print self. Name + ' The Sports meeting ' #定义一个静态方法, the implementation class can access this method @staticmethod #第一步, add a self-brought decorator def Foo (): #第二步, remove the shelf print ' anti-corruption activities ' #实例化两个对象, the object names are: HB, SDHB = Province (' Hebei ', ' Shjiazhuang ', ' Liyang ') SD = Province (' Shandong ', ' Jinan ', ' Angshenghui ') #对象访问动态方法 (Note: Class cannot access dynamic methods) Hb.sports () sd.sports () #通过类名访问静态方法Province. Foo () #那么, does the object have access to static methods? The answer is yes to HB. Foo ()