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__: (<class '__main__.Person'>,)
Employee.__dict__: {'displayEmployee': <function Employee.displayEmployee at 0x00000000006BF378>, 'displayCount': <function Employee.displayCount at 0x00000000006BF2F0>, '__module__': '__main__', 'empCount': 0, '__doc__': '\n    所有员工的基类\n    ', '__init__': <function Employee.__init__ at 0x00000000006BF1E0>}


猜你喜欢

转载自blog.csdn.net/pansc2004/article/details/80364270