Get startedGet started for free

Identifying object-oriented programs in Python

You're going through the code at your company, looking for examples of object-oriented programming, and you find the following code snippets. Based on what you've seen so far, which of the following Python programs would be considered object-oriented?

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

This exercise is part of the course

Programming Paradigm Concepts

View Course

Hands-on interactive exercise

Turn theory into action with one of our interactive exercises

Start Exercise