Python's decorator @property, turning the method into a feature

Source: Internet
Author: User

# -*- coding: utf-8 -*-"" "created on sun nov 13 23:19:03  2016@author: toby "" "#知识点: @property the method into a feature with the adorner class province:    memo =   ' one of china\ ' s 23 provinces '   #静态字段          def __init__ (self,name,capital,leadership):         self. name = name  #动态字段         self. capital = capital  #动态字段         self. leadership = leadership  #动态字段              def sports (self):  #定义一个动态方法, class cannot access dynamic methods         print  self. name +  ' the sports meeting '          #把方法变成一个特性      @property   #自带的装饰器   &NBSp; def bar (self):         print self. name        return  ' somthing '   #也是可以有一个返回值的           #实例化两个对象, the object names are: HB, sdhb = province (' Hebei ', ' Shjiazhuang ', ' Liyang ') SD  = province (' Shandong ', ' Jinan ', ' Angshenghui ') #通过对象访问这个属性, the Access form of the method becomes the Access form of the Access field PRINT HB. Bar


This article is from the "Fa&it-Q Group: 223843163" blog, please be sure to keep this source http://freshair.blog.51cto.com/8272891/1874165

Python's decorator @property, turning the method into a feature

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.