python补充知识

面向对象

  • self 代表的是类的实例,代表当前对象的地址,内含一个16进制的地址
  • self.class 则指向类。

代码1

class people:
    age = 10
    name = "liming"

age和name是全局的,修改people类的对象中的age和name会使类中相应的变量发生改变。

代码2

class Employee:
   empCount = 0
 
   def __init__(self, name, salary):
      self.name = name
      self.salary = salary
      Employee.empCount += 1
empCount 是全局变量
name、salary是Employee的对象的私有变量
init()是构造函数```
posted @ 2021-08-06 22:40  猪猪猪猪侠  阅读(41)  评论(0编辑  收藏  举报