Computer scienceProgramming languagesPythonObject-oriented programmingMethods

Methods and attributes

BFF

Report a typo

Here are a class Friend and a couple of its instances. Some of those instances called the set_best_friend method.

class Friend:
    def __init__(self, name):
        self.name = name
        self.best_friend = None

    def set_best_friend(self, bff_name):
        self.best_friend = bff_name


kate = Friend("Kate")
alex = Friend("Alex")
jess = Friend("Jess")

kate.set_best_friend("Melani")
jess.set_best_friend("Kate")
kate.set_best_friend("Jess")

What will be the output of this code?

print(kate.best_friend)
Select one option from the list
___

Create a free account to access the full topic