编程思想
面向对象
面向过程
事物较简单,可以线性思维解决
类与对象
类
类似事物组成的群体的统称
对象
类之下的相似的不同个例
类的创建
class Student:
类的组成
类属性
native_pace='AA'
实例方法
def eat(self):
print('aaaa')
静态方法
@staticmethod
def method():
print('aaaa')
类方法
@classmethod
def cm(cls):
print(aaaa)
初始化方法
def _init_(self,name,age)
self.name=name
self.age=age
对象的创建
stu1=Student('张三',20)
使用
stu1.eat()
Student.eat(stu1)
stu1.name
stu1.age
类属性调用
print(Student.native_pace)
类方法调用
Student.cm()
静态方法
Student.method()
动态绑定属性及方法
每个Student类可以创建多个实例对象
单独为一个实例对象可以绑定一个属性
stu1.gender='女'
def show():
print('f')
stu1.show=show
stu1.show()
只为stu1绑定了方法
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/95251eed3082f4d1389c58e8437b1644.png)