分类 开发 下的文章

python类

类的定义

class Student:
  native_pace ="吉林" #直接写在类里面的变量成为类属性 
 
#初始化方法
   def _init_(self,name,age):
    self.name = name
    self.age = age
 
#写在类之外定义的成为函数,在类之内定义的成为方法
    def eat(self):
      print("学生在吃饭")
 
#静态方法,不可以写self
    @staticmethod
    def method():
      print("我使用了staticmethod进行修饰,所以我是静态方法")
 
#类方法,写cls
    @classmethod
    def cm(cls):
      print("我是类方法,因为我使用了classmethod进行修饰 ")