标签:创建 instance 类的属性 派生类 定义 需要 子类 .class employee
#!/usr/bin/python
# -*- coding: UTF-8 -*-
 
class Employee:
   ‘所有员工的基类‘
   empCount = 0
 
   def __init__(self, name, salary):
      self.name = name
      self.salary = salary
      Employee.empCount += 1
   
   def displayCount(self):
     print "Total Employee %d" % Employee.empCount
 
   def displayEmployee(self):
      print "Name : ", self.name,  ", Salary: ", self.salary
      class Test:
    def prt(self):
        print(self)
        print(self.__class__)
 
t = Test()
t.prt()以上实例执行结果为:
<__main__.Test instance at 0x10d066878>
__main__.Testself 不是 python 关键字,我们把他换成 runoob 也是可以正常执行的:
你可以添加,删除,修改类的属性。
标签:创建 instance 类的属性 派生类 定义 需要 子类 .class employee
原文地址:https://www.cnblogs.com/monkey-moon/p/9180502.html