Classes

Classes are essentially a template to create your objects.

class Fruits: color = "Red" def get_color(self): return 'This is the color %s' % self.color myfruit = Fruits() print(myfruit.color) print(myfruit.get_color())

function init() is a special function that is called when the class is being initiated

class Fruits: color = "Red" def __init__(self, vcolor): self.color = vcolor def get_color(self): return 'This is the color %s' % self.color myfruit = Fruits("Yellow") print(myfruit.color) print(myfruit.get_color()) myfruit = Fruits("Orange") print(myfruit.color) print(myfruit.get_color())