ref

http://www.runoob.com/python/python-object.html

note

#!/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

__init__()方法是一种特殊的方法,被称为类的构造函数或初始化方法

当创建了这个类的实例时就会调用该方法

self代表类的实例,而非类

py: class

相关文章:

  • 2021-08-21
  • 2021-05-20
  • 2022-02-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-04
  • 2021-06-22
猜你喜欢
  • 2021-06-05
  • 2022-12-23
  • 2022-12-23
  • 2021-12-24
  • 2021-07-26
  • 2021-05-26
  • 2022-01-11
相关资源
相似解决方案