python从零开始--26 python内置类属性 __dict__ __name__ __module__ __doc__ __bases__

  • __dict__ : 类的属性(包含一个字典,由类的数据属性组成)
  • __doc__ :类的文档字符串
  • __name__: 类名
  • __module__: 类定义所在的模块(类的全名是'__main__.className',如果类位于一个导入模块mymod中,那么className.__module__ 等于 mymod)

  • __bases__ : 类的所有父类构成元素(包含了一个由所有父类组成的元组)

class Person(object):

    def __int__(self, name):
        self.name = name


class Employee(Person):
    """
    所有员工的基类
    """
    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)


print("Employee.__doc__:", Employee.__doc__)
print("Employee.__name__:", Employee.__name__)
print("Employee.__module__:", Employee.__module__)
print("Employee.__bases__:", Employee.__bases__)
print("Employee.__dict__:", Employee.__dict__)
Employee.__doc__: 
    所有员工的基类
    
Employee.__name__: Employee
Employee.__module__: __main__
Employee.__bases__: (,)
Employee.__dict__: {'displayEmployee': , 'displayCount': , '__module__': '__main__', 'empCount': 0, '__doc__': '\n    所有员工的基类\n    ', '__init__': }


你可能感兴趣的:(python从零开始--26 python内置类属性 __dict__ __name__ __module__ __doc__ __bases__)