zoukankan      html  css  js  c++  java
  • Python_方法演示

    class Root:
    __total=0
    def __init__(self,v): #构造函数
    self.__value=v
    Root.__total+=1
    def show(self): #普通实例方法
    print('self.__value:',self.__value)
    print('Root.__total:',Root.__total)

    @classmethod #修饰器,声明类方法
    def classShowTotal(cls):
    print(cls.__total)

    @staticmethod
    def staticsShowTotal():
    print(Root.__total)
    r=Root(3)
    r.classShowTotal()
    r.staticsShowTotal()
    r.show()
    rr=Root(5)
    Root.classShowTotal()
    Root.staticsShowTotal()
    Root.show(r)
    r.show()
    Root.show(rr)
    rr.show()


    ###########################输出###########################

    1
    1
    self.__value: 3
    Root.__total: 1
    2
    2
    self.__value: 3
    Root.__total: 2
    self.__value: 3
    Root.__total: 2
    self.__value: 5
    Root.__total: 2
    self.__value: 5
    Root.__total: 2



  • 相关阅读:
    第四周作业
    jsp第二次作业
    jsp第一次作业
    软件测试1
    activity
    listview
    sql
    登录
    第二次安卓作业
    安卓第一周作业
  • 原文地址:https://www.cnblogs.com/cmnz/p/6923871.html
Copyright © 2011-2022 走看看