python之类方法

1.类方法的定义需要用到@classmethod在类方法之前来声明一下

  比如:class Person(object):

      address = 'china'

      @classmethod

      def get_address(cls): // 类方法,参数为类本身,一般写为cls

        return cls.address  //返回 china,相当于Person.address

posted @ 2020-05-22 11:07  明朝乘扁舟  阅读(82)  评论(0)    收藏  举报