class Employee:
'所有员工的基类' ##这个是__doc__
empCount = 0 # 类成员变量 只能通过 Employee.empCount来赋值
def __init__(self, name, salary):
print("对象的实例化,会调用__init__")
self.name = name
self.salary = salary
Employee.empCount += 1
print ("Total Employee empCount is %d" % Employee.empCount)
def displayCount(self):
Employee.empCount+=1
print ("Total Employee %d" % Employee.empCount)
def displayEmployee(self):
print ("Name : %s,Salary: %s" %(self.name,self.salary))
def __call__(self, *args, **kwargs):
print("__call__ 是对象后加括号 employee= Employee(),这个是实例化对象 employee()这个是调用__call__")
def __str__(self):
return "this is __str__ employee 需要返回"
def main():
employee = Employee("lihui",3200) # python对象 不像java一样,必须声明 Employee employee ,直接employee= Employee();即可,那怎么声明对象是不是null呢
employee.displayCount()
employee.displayEmployee()
print("__doc__ 是python的内置函数")
print(Employee.__doc__)
print(employee.__doc__)
print("__module__ 内置函数")
print("Employee.__module__="+Employee.__module__)
print("employee.__module__:"+employee.__module__)
print("调用__call__ employee() 内置函数")
employee()
print("__dic__")
print(employee.__dict__)
print(Employee.__dict__)
print("employee")
print(employee)
print("https://blog.csdn.net/weixin_38278993/article/details/91540213 python类的内置函数 其他的参考这个")
if __name__ == "__main__":
main()