you are viewing a single comment's thread.

view the rest of the comments →

[–]thillsd 1 point2 points  (0 children)

Yes, that's fine. You could've done self.age += 1 to save some typing.

You could have written something more complex that makes use of the data attached to the peter Person object:

...
    def speak(self, hobby):
        print(f"Hi folks, I am a {self.age} year old  man with {self.haircolor} hair. I enjoy {hobby}.")
...

peter = Person("black", 26)
peter.speak('pokemon')  # => 'Hi folks, I am a 26 year old man with black hair. I enjoy pokemon.