Python 静态方法

Posted on 2018-12-27 21:25  缥缈映苍穹  阅读(129)  评论(0)    收藏  举报
class Person:

    @staticmethod # 静态方法
    def yue():
        print("fsadf")


# 静态方法可以使用对象访问. 也可以使用类名访问. 但是一般推荐使用类名访问
p = Person()
p.yue()

# 推荐使用类名访问
Person.yue()