零基础学 Python(2023 版)
尹会生
太乙人工智能技术合伙人 & 项目总监
60050 人已学习
新⼈⾸单¥68
课程目录
已完结/共 124 讲
结束语 & 结课测试 (2讲)
零基础学 Python(2023 版)
登录|注册
留言
11
收藏
沉浸
阅读
分享
手机端
回顶部
当前播放: 60|类的继承:如何解决代码重用的问题?
00:00 / 00:00
高清
  • 高清
1.0x
  • 2.0x
  • 1.5x
  • 1.25x
  • 1.0x
  • 0.75x
  • 0.5x
网页全屏
全屏
00:00
付费课程,可试看
课程介绍:这次我们都做了哪些升级?
内容综述:明确学习目的
01|如何配置 Python 开发环境?
02 | 常用 IDE:如何提高开发效率?
03 | 如何站在官方文档的肩膀上自己“造轮子”?
04 | 怎样运行你的第一行代码?
05 | 怎样使用 Gitee 管理你的代码?
06 | 学习编程有问题?去这里找答案!
07|跨越门槛:Python 开发环境总结及实现原理
08 | 修炼基本功:浅析输入输出
09 | 变量:如何让计算机临时存储数据?
10|字符串(上):Python 是如何处理单词的?
11|字符串(下):Python 是如何处理单词的?
12|存储数字应该采用哪种数据类型?
13|何时使用数,何时使用字符串?
14|注释:如何写程序的说明书?
15|小试牛刀:如何制作简单计算器?
16|变量命名规范:如何编写优雅的程序?
17|告别新手村:Python 编程基础知识
18|内置数据类型包括哪几种?
19|列表如何处理同类数据?
20|常见常新:列表的常见操作
21|元组:如何处理一次性数据?
22|常见常新:集合的常见操作
23|字典:如何处理映射类型的数据?
24|常见常新:字典的常见操作(上)
25|常见常新:字典的常见操作(下)
26|小试牛刀:如何利用类型转换实现手机通讯录?(上)
27|小试牛刀:如何利用类型转换实现手机通讯录?(下)
28|常见的内置数据类型都何时使用?
29|避坑指南:内置数据类型的常见错误
30|内置数据类型参考:如何使用官方文档与帮助?
31|再回首:“内置数据类型”单元小结
32|if 语句:数据流程出现分支时,怎样编写程序?
33|match 语句:如何通过 match 关键字来处理程序的分支逻辑?
34|while 循环:需要多次重复执行某段程序时,怎么做?
35|for 循环:如何遍历一个对象里的所有元素?
36|语句嵌套:如何处理多重循环的问题?
37|小试牛刀:如何设计一个飞机大战的程序?
38|避坑指南:判断和循环中的常见错误
39|再回首:“判断循环”单元小结
40|输入:如何接收用户通过键盘输入的数据?
41|格式化输出:如何将执行结果通过屏幕输出?
42|F-strings:如何通过定义好的格式进行输出?
43 | 常见常新:文件的打开
44|文件编码:如何解决不同操作系统的文件乱码问题?
45|常见常新:文件的读写
46|常见常新:文件的关闭
47|小试牛刀:如何使用 Python 合并多个文件?
48|再回首:“输入输出与文件操作”单元小结
49|函数的定义:如何优雅地反复引用同一段代码?
50|函数的参数:怎样实现函数与外部数据通信?
51|函数的参数:当函数操作对象不固定时怎么处理?
52|函数的返回值:如何得到函数的执行结果?
53|小试牛刀:如何利用函数实现电商购物车功能?
54|避坑指南:列表作为参数传递出错了怎么办?
55|高阶函数:函数对象与函数调用的用法区别
56|装饰器:函数嵌套的定义与调用的区别
57|再回首:“函数”单元小结
58|编程思想不同会导致怎样的代码差异?
59|类与实例:如何使用面向对象的思想编写程序?
60|类的继承:如何解决代码重用的问题?
61|类的装饰器:如何改变类方法的功能?
62|小试牛刀:如何开发自动咖啡机?
63|避坑指南:类的常见错误
64|init 方法:如何为对象传递参数?
65|再回首:“类”单元小结
66 | 模块的导入:如何使用其他人编写好的代码功能?
67 | 标准库:Python 默认提供的便捷功能有哪些?
68 | 自定义模块:如何编写一个完整功能?
69 | 第三方模块的使用:如何使用其他人编写的代码?
70 | 小试牛刀:如何使用 Python 为函数求导?
71|再回首:“模块与标准库”单元小结
72|初识异常:异常的产生与分类
73|异常捕获:出现异常时,如何利用程序进行处理?
74|自定义异常捕获:如何定义业务异常?
75|避坑指南:编写捕获异常程序时经常出现的问题
76|再回首:“异常处理”单元小结
77|扩展数据类型:怎样使用更复杂的数据类型?
78|魔术方法:怎样通过类构造自己需要的数据类型?
79|怎样将 Python 和 C++ 结合起来混合编程?
80|怎样将已有算法改造成符合项目的特定算法?
81|设计模式:怎样合理组合多个函数和类?
82|Redis 数据库:怎样使用 NoSQL 数据库?
83|关系型数据库:怎样使用关系型数据库?
84|计算资源充足时,如何通过并行设计提高效率?
85|多进程间如何通信?
86|再回首:“高级数据类型与算法”单元小结
87|理论盘点:数据分析的流程及对应的 Python 库
88|理论盘点:数据采集的方法与 HTTP 协议
89|理论盘点:任务的并行执行原理
90|理论盘点:非规范化数据处理的基础与正则表达式
91|如何获取网页上的数据并存储到文件?
92|小试牛刀:如何将数据进行图形化展示?
93|再回首:“数据分析”单元小结
94|理论盘点:文件类型与对应的 Python 函数库
95|如何批量读取 Excel 文件?
96|如何实现数据的批量格式转换?
97|如何扩展数据类型?
98|再回首:“办公自动化”单元小结
99|理论盘点:Web 客户端与服务端
100|理论盘点:MVC 模型是什么?
101|如何使用Django搭建简单的Web服务器?
102|如何使用Django-admin实现文章上传?
103|如何使用Django实现文章发布?
104|再回首:“Web开发”单元小结
105|理论盘点:人脸识别的一般步骤
106|理论盘点:人脸识别常用的 Python 库有哪些?
107|怎样通过 OpenCV 采集视频信号?
108|如何训练人脸模型?
109|怎样设计人脸识别系统?
110|再回首:“计算机视觉”单元小结
111|聚焦异同:物联网与互联网有啥不一样?
112|理论盘点:基础但不简单的 TCP 协议
113|理论盘点:物模型与模组
114|如何为 ESP32 安装 MicroPython?
115|怎样通过 MQTT 协议构建消息队列?
116|小试牛刀:在 OLED 屏幕和手机远程同时显示室内温度
117|再回首:“物联网”单元小结
118|结束语:人生苦短,我用Pyhon
结课测试|来赴一场满分之约吧!
直播加餐|与AI共同编程,用ChatGPT学Python
直播加餐|用OpenAI API理解Python数据类型
直播加餐|掌握Gradio框架:为 AI Agent 程序定制界面
本节摘要

课后习题
请结合类的继承,为童谣定义类和方法:
小老鼠,上灯台,偷油吃,下不来,喵喵喵,猫来了,叽里咕噜滚下来。

课程代码、课件及其他相关资料地址
https://gitee.com/wilsonyin/zero-basics-python

登录 后留言

全部留言(11)

  • 最新
  • 精选
Geek_219b52
个人理解,不使用super(),就不会去找父类下面的run()方法,还是执行了自己(子类)的run()方法 class Father(object): def run(self): print("run is father") class Son(Father): def run(self): # super().run() print("run is son") cz = Father() cz.run() cxt = Son() cxt.run()

作者回复: 我帮你补充一下super() 的定义, super() 是 Python 的一个内建函数,它用于调用父类(或多个祖先类)中的方法。这个函数在处理继承和多重继承时尤为有用。在 Python 3 中,super() 和 super(ClassName, self) 基本上是等价的,但 super() 更简洁。 class Parent: def hello(self): print("Calling parent method") class Child(Parent): def hello(self): super().hello() print("Calling child method") c = Child() c.hello() 输出结果 Calling parent method Calling child method 在上面的例子中,Child 类覆盖了 Parent 类的 hello 方法。在 Child 类的 hello 方法中,我们使用 super().hello() 调用了 Parent 类的 hello 方法。

2023-08-17
繁星不灭
1.习题练习 class Animal(): #定义动物类 def move(self,animal,location,destination,distance,direction): #方法:动物能移动 print(f"The {animal} moved {distance} meter {direction} from the {location} to the {destination}") def bark(self,animal,sound): #方法:动物能发出声音 print(f"The {animal} make a {sound} sound") def eat(self,animal,eat_thing): #方法:动物能吃东西 print(f"The {animal} eat {eat_thing}") #实例化一只老鼠 mouse=Animal() #实例化一只猫 cat=Animal() #老鼠上灯台 mouse.move("mouse","ground","Menorah",0.5,"upward") #老鼠偷油吃 mouse.eat("mouse","oil") #老鼠下不来 mouse.move("mouse","Menorah","Menorah",0,"down") #猫喵喵喵 cat.bark("cat","喵喵喵") #猫来了 cat.move("cat","room","ground",5,"left") #老鼠叽里咕噜滚下来 mouse.bark("mouse","叽里咕噜") mouse.move("mouse","Menorah","ground",0.5,"down") 2.输出结果 The mouse moved 0.5 meter upward from the ground to the Menorah The mouse eat oil The mouse moved 0 meter down from the Menorah to the Menorah The cat make a 喵喵喵 sound The cat moved 5 meter left from the room to the ground The mouse make a 叽里咕噜 sound The mouse moved 0.5 meter down from the Menorah to the ground
2023-01-12
10
yanyu-xin
class Animal(object): '''动物类''' def __init__(self, name): self.name = name def action_roll(self): self.act = ' roll ' def action_walk(self): self.act = ' walk' def action_crawl(self): self.act = ' crawl' def direction_up(self): self.act_direction = ' up' def direction_down(self): self.act_direction = ' down' def direction_here(self): self.act_direction = ' come here' def action_sound(self, sound): self.act_sound = sound def action_location(self, location): self.act_location = location class Cat(Animal) : ''' 猫''' def __init__(self, name): super().__init__(name) self.name=name def cry(self): self.sound =' mews [ miaows ]' class Mouse(Animal) : '''老鼠 ''' def __init__(self, name): super().__init__(name) self.name = name def cry(self): self.sound =' squeak goes the rat' def eat_oil(self): self.act = ' steal oil to eat. ' def refuse_down(self): self.act = ' refuse to come down' Tom = Cat('Tom') Jerry= Mouse('Jerry') # 小老鼠,上灯台 Jerry.action_crawl() Jerry.direction_up() Jerry.action_location(' lampstand') str1 = Jerry.name + Jerry.act + Jerry.act_direction + Jerry.act_location # 偷油吃 Jerry.eat_oil() str2 = Jerry.name + Jerry.act # 吱吱叫,下不来 Jerry.cry() Jerry.refuse_down() str3 = Jerry.name + Jerry.act str4 = Jerry.name + Jerry.sound # 喵喵喵 Tom.cry() str5 = Tom.name + Tom.sound # 猫来了 Tom.action_walk() Tom.direction_here() str6 = Tom.name + Tom.act + Tom.act_direction # 叽里咕噜滚下来 Jerry.action_roll() Jerry.direction_down() Jerry.action_sound(' rumble ') Jerry.action_location(' floor ') str7 = Jerry.name + Jerry.act + Jerry.act_direction + Jerry.act_location + Jerry.act_sound print(f'{str1},\n{str2},\n{str3},\n{str4},\n{str5},\n{str6},\n{str7}.')
2023-02-13
2
Seven
不实用super()会报错, NameError: name 'run' is not defined, 调用了一个未定义的方法
2023-01-24
2
Geek_Mike
# 请结合类的继承,为童谣定义类和方法:小老鼠,上灯台,偷油吃,下不来,喵喵喵,猫来了,叽里咕噜滚下来。 class Animal(): def __init__(self, name, sound): self.name = name self.sound = sound def show_up(self): print(f'{self.sound}, {self.name}来了,') class Mouse(Animal): def show_up(self): super().show_up() print('上灯台,偷油吃,下不来') class Cat(Animal): def show_up(self): super().show_up() print('叽里咕噜滚下来') little_mouse = Mouse(name='小老鼠',sound='吱吱吱') little_cat = Cat(name='小猫咪',sound='喵喵喵') little_mouse.show_up() little_cat.show_up()
2023-07-29
1
江江儿嘛哩哄
class Animal(object): def func(self): print("It can run and bark") class Mouse(Animal): def func(self): super().func() print("It climb onto the candlestick ") class Cat(Animal): def func(self): super().func() print("It can catch mouse") obj = Animal() obj.func() obj1 = Mouse() obj1.func() obj2 = Cat() obj2.func()
2023-01-12
1
Geek_c131f7
class animal: size = 0 life = 1 def move(self): print('medium') pass class mouse(animal): size = 'small' def move(self): super().move() print('上灯台') print('偷油吃') class cat(animal): size = 'bigger' def move(self): super().move() print('喵')
2024-03-22
Geek_0c747b
这是一个使用类和继承来描述这个童谣的 Python 代码示例: ```python class Animal: def __init__(self, name): self.name = name def make_sound(self): pass class Mouse(Animal): def __init__(self): super().__init__("小老鼠") def climb(self): print(f"{self.name},上灯台") def eat_oil(self): print(f"{self.name},偷油吃") def cannot_get_down(self): print(f"{self.name},下不来") class Cat(Animal): def __init__(self): super().__init__("猫") def make_sound(self): print(f"喵喵喵,{self.name}来了") mouse = Mouse() mouse.climb() mouse.eat_oil() mouse.cannot_get_down() cat = Cat() cat.make_sound() print("叽里咕噜滚下来") ``` 在这个代码中,我们首先定义了一个基类 `Animal`,它有一个 `name` 属性和一个 `make_sound` 方法。然后我们定义了两个继承自 `Animal` 的子类:`Mouse` 和 `Cat`。`Mouse` 类有 `climb`、`eat_oil` 和 `cannot_get_down` 方法来描述小老鼠的行为。`Cat` 类重写了 `make_sound` 方法来描述猫的叫声。最后,我们创建了一个 `Mouse` 对象和一个 `Cat` 对象,并调用了它们的方法来讲述童谣的故事。 .
2023-12-07
Geek_377ac8
class Father(object): def run(self): print("父类的run") class Son(Father): def run(self): self.run() print("子类的run") obj = Father() obj1 = Son() obj1.run() 如果不用super()方法调用父类的方法,而直接用self调用父类方法,会报递归错误 猜测原因可能是在子类中self.run()属于自己调用自己,没有办法退出,导致了死循环
2023-11-30
依托答辩
# 动物基类 class Animal: def __init__(self, name, sound): self.name = name self.sound = sound def walk(self): print('能走路') def run(self): print('能跑') def sound(self): print('能叫') def show(self): print(self.name, self.sound) # 混入 class UpMixin: def up(self): print('上灯台, 下不来') class RollDownMixin: def roll(self): print('叽里咕噜滚下来') # 小老鼠 class Mouse(Animal, UpMixin, RollDownMixin): def show(self): super().show() super().up() def roll(self): super().roll() # 猫 class Cat(Animal): def show(self): super().show() print('猫来了') mouse = Mouse('小老鼠', '吱吱吱') mouse.show() cat = Cat('猫', '喵喵喵') cat.show() mouse.roll()
2023-11-27
收起评论