Python uses the decorator @ property to convert the method into a feature instance.

Source: Internet
Author: User
Tags python decorator
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!

Related Article

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.