How do i define a method in a python class?
-
Also see: https://www.lightnetics.com/post/9836
From previous articles we are using the same
class Cake(object): def __init__(self, type, base): self.type = type self.base = base def mycake(self): print("This is the type of cake: " + self.type) print("This is the base layer of the cake: " + self.base)
This class has two methods, a special init method and mycake. The mycake is calling the init method. The mycake is only printing some simple lines however, it can be as complex as you need to make it.
© Lightnetics 2024