This article describes how to use the modifier @ property to convert a method into a feature instance in python, interested friends can refer to this article for details about how to use the python decorator @ property to turn the method into a feature instance. interested friends can refer
#-*-Coding: UTF-8-*-"Created on Sun Nov 13 23:19:03 2016 @ author: toby" "# Knowledge Point: decorator @ property, convert the method into a feature class Province: memo = 'one of China \'s 23 provinces '# static field def _ init _ (self, name, capital, leadership ): self. name = name # dynamic field self. capital = capital # dynamic field self. leadership = leadership # dynamic field def sports (self): # defines a dynamic method. the class cannot access the dynamic method print self. name + 'The sports meeting '# Convert The method into a feature @ property # The built-in decorator def Bar (self): print self. name return 'sommthing '# can also have a return value # instantiate two objects, the object names are: hb, sdhb = Province ('hebei', 'shjiazhuang', 'liyang ') sd = Province ('Shandong ', 'json', 'angshenghu') # use an object to access this attribute and convert the method access form to the access field access form print hb. bar
The above is the details of converting the method into a feature instance using the modifier @ property in python. For more information, see other related articles in the first PHP community!