C++的静态方法是用static关键字,python j是没用static的。

python中实现静态方法和类方法都是依赖于python的修饰器来实现的。

class MyClass: 

    def  method(self): 

           print("method") 

    @staticmethod 

    def  staticMethod()

            print("static method") 

     @classmethod 

     def classMethod(cls)

           print("class method") 

 

大家注意到普通的对象方法、类方法和静态方法的去别了吗?

对象方法有self参数,类方法有cls参数,静态方法是不需要这些附加参数的。

在C++中是没有类方法着个概念的的

相关文章:

  • 2021-10-23
  • 2021-08-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2018-06-30
  • 2021-09-17
猜你喜欢
  • 2022-02-24
  • 2021-09-17
  • 2021-08-28
  • 2022-12-23
  • 2022-12-23
  • 2021-06-30
相关资源
相似解决方案