請參考下面代碼,分別說出1-19題運行結果,及緣由。python
class Person(object): __country = 'China' def __init__(self, name, age): self.__name = name self.age = age def query(self): Person.query_cls1() def query2(self): Person.query_cls3() def __query(self): Person.query_cls6() def __query2(self): print('hello') @classmethod def query_cls1(cls): print(cls.__country) @classmethod def query_cls2(cls): print(cls.name) @classmethod def query_cls3(cls): cls.query() @classmethod def query_cls3_2(cls): gf = Person('林小花', 18) cls.query(gf) @classmethod def query_cls4(cls): cls.__query() @classmethod def query_cls4_1(cls): gf = Person('林小花', 18) gf.__query2() @classmethod def query_cls4_2(cls): cls._Person__query() @classmethod def query_cls5(cls): cls.query_sta1() @classmethod def query_cls6(cls): print('hello boy') @staticmethod def query_sta1(): Person.query_cls1() @staticmethod def query_sta2(): Person.__query() @staticmethod def query_sta3(): Person._Person__query() @staticmethod def query_sta4(): gf = Person('林小花', 18) Person._Person__query(gf)
特別說明:__query2這個方法後面的全部方法上面都有裝飾器,spa
博客裏面沒顯示出來,是博客的bug吧,要選中才顯示,最好複製出來看blog
1博客
Person.query_cls1()
2it
Person.query_cls2()
3class
gf = Person('林小花', 18)
Person.query_cls2(gf)
4object
Person.query()
5bug
Person.query_cls3()
6方法
gf = Person('林小花', 18)
Person.query(gf)
7裝飾器
gf = Person('林小花', 18)
Person.query_cls3(gf)
8
Person.query_cls3_2()
9
Person.__query()
10
Person.query_cls4()
11
Person.query_cls4_1()
12
Person._Person__query()
13
Person.query_cls4_2()
14
gf = Person('林小花', 18)
Person.__query(gf)
15
gf = Person('林小花', 18)
Person._Person__query(gf)
16
Person.query_sta1()
17
Person.query_sta2()
18
Person.query_sta3()
19
Person.query_sta4()