PYTHON OOP: Tutorial 1

YouTube

Data & Functions = Attributes & Methods (when talking about a class)

In [16]:
class Cat:
    
    #Init/initialize (like a constructor)

    def __init__(self, name, color, gender):
        self.name = name
        self.color = color
        self.gender = gender
    
    def introduction(self):
        return "Hi! I'm {}. A {}, {} cat.".format(self.name, self.color, self.gender)
In [17]:
uli = Cat('Uli', 'Gray', 'Male')
In [18]:
uli.color
Out[18]:
'Gray'
In [19]:
Cat.introduction(uli)
Out[19]:
"Hi! I'm Uli. A Gray, Male cat."
In [ ]: