首页 > 编程语言 > 详细

Python类方法,静态方法

时间:2019-04-16 22:12:06      阅读:143      评论:0      收藏:0      [点我收藏+]
class Student:
    company = LOL
    @classmethod
    def say_company(cls):
        print(cls.company)

Student.say_company()
与类方法界限不清晰,可以访问类,只是不通过CLS


class
Student: company = LOL @staticmethod def add(a,b): print(Student.company) print("{0}+{1}={2}".format(a,b,a+b)) Student.add(1,2)

两种方法多不能访问实例变量。

Python类方法,静态方法

原文:https://www.cnblogs.com/zzm-blog/p/10720333.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!