开始使用免费开始使用

识别 Python 中的面向对象程序

您正在审查公司里的代码,想找出面向对象编程的示例,并发现了以下代码片段。基于目前为止您所学的内容,以下哪些 Python 程序可被视为面向对象?

Program A:

def buy_car(make, model, price):
    print("You've bought a ", make, model, "for $", price, "!")

Program B:

class Car():
    def __init__(self, make, model):
        self.make = make
        self.model = model

本练习是课程的一部分

编程范式概念

查看课程

动手互动练习

通过我们的互动练习之一,将理论转化为实践

开始练习