1 2 3 4 5 ··· 9 下一页
摘要: 12.8 类与对象的绑定方法和非绑定方法 绑定方法:方法绑定给对象使用。 对象的绑定方法:没有加任何装饰的方法就是对象的绑定方法;只有对象能用,类也能使用,类使用时必须传参数。 类的绑定方法:加了@classmethod装饰器的方法就是类的绑定方法;类能使用,对象也能使用,但是数据类型依然是类;不需 阅读全文
posted @ 2025-09-08 20:43 bokebanla 阅读(14) 评论(0) 推荐(0)
摘要: 12.7 类的property/setter/delter特性 装饰器加到函数上,不能加到属性上 class People(): def __init__(self,height,weight): self.height=height self.weight=weight @property #获取 阅读全文
posted @ 2025-09-08 20:33 bokebanla 阅读(8) 评论(0) 推荐(0)
摘要: 目录12.6 类的封装1. 封装的两个层面2. 封装的好处3.获取封装的属性或方法(了解) 12.6 类的封装 封装是什么?打包,封起来,装起来。封装是针对类的, 封装分为两个层面: 第一个层面:对象能拿到类的东西,但是类不能拿到对象的东西。 第二个层面:内部可以使用,外部不可以使用、在需要封装的属 阅读全文
posted @ 2025-09-08 20:14 bokebanla 阅读(11) 评论(0) 推荐(0)
摘要: 12.5 多态与多态性 多态:一种事物有多种形态,只要大家都能继承A,那么这些东西就是A的多态 水:固态/液态/气态 动物:人/狗/猫 class Animal: def __init__(self,height,weight): self.height=height self.weight=wei 阅读全文
posted @ 2025-09-08 19:57 bokebanla 阅读(10) 评论(0) 推荐(0)
摘要: 12.4 菱形继承问题(了解) 1.经典类和新式类 新式类:在python中会默认继承object类,只要继承了object类的就是新式类,python3中所有类都是新式类。 经典类:没有继承object的就是经典类,只有python2中有经典类。 2.菱形继承问题 当继承为菱形继承的时候经典类和新 阅读全文
posted @ 2025-09-08 19:50 bokebanla 阅读(9) 评论(0) 推荐(0)
摘要: 12.3 类的组合 把对象当做变量值来用,当做形参/实参/返回值 类似于:把函数作为参数,作为返回值。 #简单的选课系统 #父类 class People: def __init__(self,name,gender): self.name=name self.gender=gender def e 阅读全文
posted @ 2025-09-08 19:46 bokebanla 阅读(13) 评论(0) 推荐(0)
摘要: 12.2 类的派生 1.类的查找顺序 #父类 class Foo: def f1(self): print('Foo.f1') def f2(self): #b print('Foo.f2') self.f1() #子类 class Bar(Foo): def f1(self): print('Ba 阅读全文
posted @ 2025-09-08 19:43 bokebanla 阅读(11) 评论(0) 推荐(0)
摘要: 12.1 类的继承 在python中,父类和子类(派生类)只有在继承的时候会产生。 继承为了拿到父类的属性和方法 #定义父类 class Parent_Foo(): def __init__(self,first_name,money,car,house): self.first_name=firs 阅读全文
posted @ 2025-09-08 19:23 bokebanla 阅读(11) 评论(0) 推荐(0)
摘要: 11.5 类与数据类型 什么是数据类型:int/float/str/dict/list/tuple/set #列表的定义 lis=[1,2,3] lis=list([1,2,3]) class Foo: pass f1=Foo() print(type(f1)) #输出:<class '__main 阅读全文
posted @ 2025-09-08 19:06 bokebanla 阅读(6) 评论(0) 推荐(0)
摘要: 11.4 类与对象的绑定方法 对象作为参数传入类中方法的形参self class OldBoyStudent: school='oldboy' name=0 count=0 def __init__(self,id,name,age): #self也可以是其他变量名,例如aaa、b,只是self是约 阅读全文
posted @ 2025-09-08 18:50 bokebanla 阅读(8) 评论(0) 推荐(0)
1 2 3 4 5 ··· 9 下一页