Skip to content Skip to sidebar Skip to footer

Creating A Method In Object Oriented Programming With Python

I'm learning object oriented programming in python and I'm not too sure how to write methods for classes My first question is, can you inherit two classes at the same time? Exampl

Solution 1:

First question. Answer is yes.

You need something after the class definition. Sometimes all the behaviour is defined by A and B, so you just need to put pass there (or a docstring)

class C(A, B):
    pass

Second question: append is a function, you need to call it with parentheses

self.add.append((name, hair))

You can't have an attribute add and a method add as they share the same namespace. Whichever one you define last will replace the other

Post a Comment for "Creating A Method In Object Oriented Programming With Python"