学习小结(9)

1、面向对象

       class Test():     #class来定义类

              country = 'China'      # 类变量  直接定义在类中的

              #实例方法  必须实例化才能调用

              def my(self):      #没有self 相当于静态方法。

                print(self.country)

       a = Test()    # 类名加()就是实例化 ,其中a是对象也是实例

       print(a.country)

       a.my()

       a.country = 'Jap'  #给a的对象绑定了一个属性。

       print(a.country)

       print(Test.country)

思考:

       1、总共会print几次

       2、每次print都是什么

原文地址:https://www.cnblogs.com/cslw5566/p/9102516.html