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>}


  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值