Python Practice › OOP Programs › Program 47
Animal class
Create Animal with name and colour and a method to print them.
Output
Bruno is brown
Approach
- Store and print.
Solution
class Animal: def __init__(self, name, color): self.name, self.color = name, color def show(self): print(f"{self.name} is {self.color}") Animal("Bruno", "brown").show()Output
Bruno is brown
Learn the concept
New to this topic? Read the lesson, then come back.