• 技术文章 >常见问题 >Python常见问题

    python看类里有哪些方法

    silencementsilencement2020-02-11 15:15:35原创2710

    Python使用 class 语句来创建一个新类,class 之后为类的名称并以冒号结尾:

    1

    2

    3

    class ClassName:

       '类的帮助信息'   #类文档字符串

       class_suite  #类体

    实例

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    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

    通常,类中的函数被称为方法,查看类中有几个函数,就能确定有几个方法。

    推荐学习《Python教程》。

    专题推荐:class
    上一篇:python按f5为什么不运行 下一篇:python工具包如何安装

    相关文章推荐

    • python抽象基类之_subclasshook_方法• python的class怎么用• python如何定义class

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网