zoukankan      html  css  js  c++  java
  • python面向对象装饰器

    @property 装饰过的函数返回的不再是一个函数,而是一个property对象
              装饰过后的方法不再是可调用的对象,可以看做数据属性直接访问。
    @staticmethod 把没有参数的函数装饰过后变成可被实例调用的函数,
                 函数定义时是没有参数的。
    @classmethod 把装饰过的方法变成一个classmethod类对象,既能能被类调用又能被实例调用。
     注意参数是cls代表这个类本身。而是用实例的方法只能被实例调用。  
    class Rectangle:
        def __init__(self,width,height):
            self.width = width
            self.height = height
        @property
        def area(self):
            return self.width*self.height
        @staticmethod
        def fun():
            return 'xxxxxx'
        @classmethod
        def show(cls):
            return 'yyyyyy'
  • 相关阅读:
    分页系统
    ORM-数据处理
    Django的用法
    登录cookie写法
    MySQL数据库的安装创建
    前端弹框编写
    ADB常用指令
    Appium环境配置
    Jmeter中传递cookie值
    Jmeter从文件中读取参数值
  • 原文地址:https://www.cnblogs.com/tudoo/p/14381319.html
Copyright © 2011-2022 走看看