第4.2讲-python类.pptx - Python 语法基础 � 教师:丛培盛 [email protected] 模块化带来的优� 计算机制造: CPU

第4.2讲-python类.pptx - Python 语法基础 �...

This preview shows page 1 - 7 out of 23 pages.

[email protected] Python 语法基础 教师:丛培盛
Image of page 1
2 模块化带来的优势 计算机制造: CPU 、显示器、主机板、键盘、机壳 汽车生产 发动机 、车外壳、轮胎、底盘 造房子 、城市高架路、高铁: 砖头、混凝土构件、窗子、门等
Image of page 2
3 程序的模块化—面向数据流 以函数为基础:处理数据流 例如,计算汽车的速率: 计算速率函数 getVolecity(r, rpm) :将某辆汽车的轮胎 半径、转速输入,计算汽车的速度。 换挡函数 changeRPM(grade) :编写一个变更转速的函 例子:计算汽车 A 的速率 RPM = changeRPM(A 车的 3 ) V=getVolecity(A 车轮胎半径 , RPM) RPM= changeRPM(A 车的 5 ) V=getVolecity(A 车轮胎半径 , RPM)
Image of page 3
4 程序的模块化—面向对象 某辆汽车,有自己的轮胎(半径已知)、变速箱(各档位 转速已知)。 将变速、计算速度代码和属性(轮胎半径等)作为一个整 体。 汽车 A.changeRPM(3 ) V= 汽车 A.getVolecity() 汽车 B. changeRPM(5 ) V= 汽车 B.getVolecity() 由于数据与处理数据的 代码,是一个整体,封 装,所以更健壮、更易 复用。
Image of page 4
5 面向对象 OOP 基础 -- 类 每类事物中的个体,有共同的属性和行为: 人:有五官、四肢,能行走、说话 汽车:有发动机、轮胎、跑 手机:颜色、尺寸、电话号码本、可以打电话、发微信 客观世界中存在的事物,可以归结为不同的类, 例如:球、人、书、猫科动物、狮子、手机、汽车,建筑物,树 OOP 认为: 事物的属性和行为是分不开的,是一个统一的整体 例如:姚明走 10 步,和你走 10 步,走出的距离不一样,因为姚明 的腿长,属性值不一样
Image of page 5
6 对象与类 类是一类事物的抽象,例如我们说手机,只能大概的说出 一些它应该有的性质及功能 对象:是类中某个明确的个体,内容很具体。 例如 小米 5 手机,我们就知道它的屏幕大小,具体的功能 ,比手机这个概念要具体很多 朱芃琦的小米 5 手机,则更具体,因为彻底具体化
Image of page 6
Image of page 7

You've reached the end of your free preview.

Want to read all 23 pages?

  • Spring '09
  • FAREWELL

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes